- Method reference is another way of creating anonymous methods. Basically, what is does is - it creates
implicit lambda function that invokes the specified method underneath. For example,
is the shorthand of
Stream.of(1.5, 2.1, 3.2).map(Double::intValue).collect(Collectors.toList());
Stream.of(1.5, 2.1, 3.2).map(d -> d.intValue()).collect(Collectors.toList());
- There are 4 types of method reference:
- Instance method reference. Reference to parameter object's method
- Other object's method reference. Reference to another instance's method.
For example,
System.out::println
- Static method reference. For example,
Arrays::asList
- Constructor reference. Used to create new object using no-arg constructor.
For example,
HashMap::new
sabyrzhan / java-notes Goto Github PK
View Code? Open in Web Editor NEW๐ ๐ฅ ๐ค My Java knowledge notes