Operator dot and Double Colon in Functional Interface

Practical Example:

 


 

Question :

 

Stream<T> filter(Predicate<? super T> predicate);
void forEach(Consumer<? super T> action);
Stream<T> sorted(Comparator<? super T> comparator);

lists.stream().filter(?).sorted(?).forEach(?);


when ever given input paremater (?) class.Functional() ?

when ever given input paremater (?) class::Functional ?

 

Answer :

The aim is into input a Functional

The class. Functional() => Transport one @FunctionalInterface as parameter

The class::Functional => Function reference directly as parameter

 

Example case foreach

void forEach(Consumer<? super T> action);
Request paramater is FunctionalInterface Consumer
The Consumer without return any value so we can print value or writing file, network transfer ...

Example has:

Class AA has the functions return Consumer<T>
Class BB has the function is Consumer<T>, itself is a Consumer<T> because the functions not return any value.

 

 Using single colon and double colon.



Thank you all everything


 

0 comments :

Post a Comment

Cancel Reply

About Me

My photo
Tân An, Long An, Vietnam
Hello everyone, I love programming, I love making friends with people all over the world.