Skip to content

Instantly share code, notes, and snippets.

@johnynek
Created March 3, 2019 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnynek/f4d122aa25e632584a8e74a09c25b182 to your computer and use it in GitHub Desktop.
Save johnynek/f4d122aa25e632584a8e74a09c25b182 to your computer and use it in GitHub Desktop.
class B { }
class Main {
public static void main(String[] args) {
B strMain = Main.<String>cast("this is not a b");
System.out.println(strMain.toString());
}
public static <A extends Object> B cast(A a) {
B[] ary = new B[1];
put(ary, a);
return ary[0];
}
public static void put(Object[] ary, Object o) {
ary[0] = o;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment