Skip to content

Instantly share code, notes, and snippets.

@skuzzle
Created March 31, 2022 15:27
Show Gist options
  • Save skuzzle/3257a0b5f11f5cc15855a1fe9db7d5a3 to your computer and use it in GitHub Desktop.
Save skuzzle/3257a0b5f11f5cc15855a1fe9db7d5a3 to your computer and use it in GitHub Desktop.
Fun with raw types
package test;
import java.util.Optional;
public class Test {
interface GenericInterface<T> {
Optional<String> methodReturningOptionalOfString();
}
String does_not_compile_with_javac_but_eclipse(GenericInterface rawReference) {
return Optional.of("asdasd")
.or(() -> rawReference.methodReturningOptionalOfString())
.orElse(null);
}
String does_not_compile_with_eclipse(GenericInterface rawReference) {
return rawReference.methodReturningOptionalOfString().orElse(null);
}
String does_compile(GenericInterface rawReference) {
return Optional.of("asdasd")
.or(() -> (Optional<String>) rawReference.methodReturningOptionalOfString())
.orElse(null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment