Last active
April 6, 2016 11:57
-
-
Save oxbowlakes/26a8d2aae6304dca8f2af4ae2664891e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.util.*; | |
class Unchecked { | |
static class Foo<A> { | |
Optional<A> doIt(Object o) { return Optional.of((A) o);} | |
} | |
public static void main(String[] args) { | |
System.out.println(new Foo<String>().doIt(3)); | |
} | |
} | |
/* compile it */ | |
//javac Unchecked.java | |
//Note: Unchecked.java uses unchecked or unsafe operations. | |
//Note: Recompile with -Xlint:unchecked for details. | |
//javac -Xlint:unchecked Unchecked.java | |
//Unchecked.java:4: warning: [unchecked] unchecked cast | |
// Optional<A> doIt(Object o) { return Optional.of((A) o);} | |
// ^ | |
// required: A | |
// found: Object | |
// where A is a type-variable: | |
// A extends Object declared in class Foo | |
//1 warning | |
/* Run it */ | |
//java Unchecked | |
//Optional[3] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment