Skip to content

Instantly share code, notes, and snippets.

@jvz
Last active January 1, 2016 11:39
Show Gist options
  • Save jvz/8139725 to your computer and use it in GitHub Desktop.
Save jvz/8139725 to your computer and use it in GitHub Desktop.
A possible abuse of Java generics.
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