r/java Sep 19 '18

JEP draft: Concise Method Bodies

http://openjdk.java.net/jeps/8209434
62 Upvotes

51 comments sorted by

View all comments

2

u/jhg023123 Sep 19 '18

Why both = and ->?

10

u/dpash Sep 19 '18

Because they do different things. = is saying that the method is the same as the method handle, and will return what ever the original method returns. -> would return a method handle (and ignore the parameter).

public boolean isEmpty(String s) = String::isEmpty;
public Predicate<String> isEmpty(String s) -> String::isEmpty; 

Does that make sense?

2

u/jhg023123 Sep 19 '18

Oh, I never thought about it like that. Thanks!