Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nipafx/ee74562769cebbf57d890c2b659b990c to your computer and use it in GitHub Desktop.
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`
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