Last active
January 1, 2016 11:39
-
-
Save jvz/8139725 to your computer and use it in GitHub Desktop.
A possible abuse of Java generics.
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 AutoCast { | |
@SuppressWarnings("unchecked") | |
public static <T> T cast(final Object object) { | |
return (T) object; | |
} | |
public static void main(final String... args) { | |
final String s = "test"; | |
final Object o = s; | |
final String t = cast(o); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment