Created
May 25, 2016 10:49
-
-
Save nipafx/ee74562769cebbf57d890c2b659b990c to your computer and use it in GitHub Desktop.
How cool would it be if `class::foo` would be a method reference to the static method `foo`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MethodReferencesToStaticMethodsDemo { | |
public Optional<String> firstSpecialString(Collection<String> strings) { | |
return strings.stream() | |
.filter(MethodReferencesToStaticMethodsDemo::isSpecial) | |
.findFirst(); | |
} | |
public Optional<String> anySpecialString(Collection<String> strings) { | |
return strings.stream() | |
// does not work but would be so cool! | |
.filter(class::isSpecial) | |
.findAny(); | |
} | |
private static boolean isSpecial(String s) { | |
return s.length() == 42; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment