我遇到了以下我不認識的Java語法。Java中的語法意味着什麼:new Stream <Integer>(){...}?
這部分是好的:
public abstract class Stream<T> implements Iterator<T> {
public boolean hasNext() {
return true; }
public void remove() {
throw new RuntimeException("Unsupported Operation"); }
}
但是,這我不明白:
Stream<Integer> ones = new Stream<Integer>() {
public Integer next() {
return 1; }
};
while(true){
System.out.print(ones.next() + ", ");
}
它是什麼?