Skip to content

Instantly share code, notes, and snippets.

@subh007
Created May 2, 2017 11:57
Show Gist options
  • Save subh007/1ae329f5ae26c2d0c4ece62b05328656 to your computer and use it in GitHub Desktop.
Save subh007/1ae329f5ae26c2d0c4ece62b05328656 to your computer and use it in GitHub Desktop.
Understand Method reference
import java.awt.Color;
import java.util.function.Function;
public class Main {
public static void execute(Function<NewBrightColor, Color> func) {
func.apply(new NewBrightColor());
}
public static void main(String[] args) {
// Reference to an instance method of an arbitrary object of a particular type
NewBrightColor brightColor = new NewBrightColor();
Function <Color, Color> fun2 = brightColor::getBrightColor1;
// Reference to an instance method of a particular object
Function <NewBrightColor, Color> func1 = NewBrightColor::getBrightColor;
//So when we call func1.apply(color) we call color.getBrightColor and return the result.
}
}
class NewBrightColor {
public Color getBrightColor() {
return null;
}
public Color getBrightColor1(Color Color) {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment