What does the syntax mean in Java: new Stream(){ … }?

后端 未结 3 652
夕颜
夕颜 2021-01-20 23:30

I have encountered the following Java syntax that I don\'t recognize.

This part is fine:

public abstract class Stream implements Iterator

        
3条回答
  •  感情败类
    2021-01-20 23:55

    ones = new Stream() {
    public Integer next() {
    return 1; }
    };

    Assigns a new instance of an anonymous implementation of Stream (that contains a virtually unlimited number of 1s. You may find more on anonymous classes in Java In A Nutshell

提交回复
热议问题