I am newbiew in Java programming. I've stuck on streams learning at this moment. Please, review two code areas below, which are parts of streams creation:
- for Sink interface (extends from interface java/util/function/Consumer)/ nested class ChainedReference
abstract static class ChainedReference<T, E_OUT> implements Sink<T> {
protected final Sink<? super E_OUT> downstream;
public ChainedReference(Sink<? super E_OUT> downstream) {
this.downstream = Objects.requireNonNull(downstream);
}
...
}
- for abstract class ReferencePipeline (extends from AbstractPipeline)/ opWrapSink method
@Override
Sink<P_OUT> opWrapSink(int flags, Sink<P_OUT> sink) {
**return new Sink.ChainedReference**<P_OUT, P_OUT>(sink) {
@Override
public void begin(long size) {...}
@Override
public void accept(P_OUT u) {...}
};
}
Could you advice how operator "new" works in code "return new Sink.ChainedReference"? From one hand, abstract classes cannot have instances. From another hand, we use operator "new" to create a class instance. In curly brackets, code authors override methods and sometimes add new variables. Can we use operator "new" with abstract static class constructor to override methods and define new variables?
Best Regards
I've expected that operator "new" couldn't be used with abstract classes