What does the syntax mean in Java: new Stream<Integer>(){ … }?
问题 I have encountered the following Java syntax that I don't recognize. This part is fine: public abstract class Stream<T> implements Iterator<T> { public boolean hasNext() { return true; } public void remove() { throw new RuntimeException("Unsupported Operation"); } } But this I don't get: Stream<Integer> ones = new Stream<Integer>() { public Integer next() { return 1; } }; while(true){ System.out.print(ones.next() + ", "); } What it is? 回答1: This is providing an inline (anonymous) subclass of