Created
March 31, 2022 15:27
-
-
Save skuzzle/3257a0b5f11f5cc15855a1fe9db7d5a3 to your computer and use it in GitHub Desktop.
Fun with raw types
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
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