Are there delegates in Java 8?
delegates, java, java-8, lambda
Solution
There are no delegates in JDK 8. Under the hood lambdas are instances of functional interfaces (an interface with exactly one abstract method). Depending on where you are passing your lambda the compiler can figure out what interface it is implementing. For example the Collections.sort method accepts a Comparator instance as a second parameter. The Comparator happens to be a functional interface so the compiler will check if the lambda you are passing matches the abstract method in Comparator or not.
A Method reference is just a simplification. When your lambda is just calling an existing method you can use this new syntax to simplify the construct. The example from the linked tutorial shows it pretty well:
instead of:
Arrays.sort(rosterAsArray,
(a, b) -> Person.compareByAge(a, b)
);
it's simpler with method reference:
Arrays.sort(rosterAsArray, Person::compareByAge);
Have a look on the lambdafaq.
Problem
Are there delegates in Java 8? If not, how do we have lambda expressions in JDK 8 without delegates? What are method references? Are they the same as delegates?