Skip to content

Instantly share code, notes, and snippets.

@boq
Created January 8, 2015 19:03
Show Gist options
  • Select an option

  • Save boq/b5474839a9f6a40f5d7f to your computer and use it in GitHub Desktop.

Select an option

Save boq/b5474839a9f6a40f5d7f to your computer and use it in GitHub Desktop.
public class GenericTest {
public static <T extends java.lang.Number> T test(java.lang.Object);
Code:
0: aload_0
1: checkcast #18 // class java/lang/Number
4: areturn
public static void test();
Code:
0: iconst_1
1: invokestatic #22 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
4: invokestatic #28 // Method test:(Ljava/lang/Object;)Ljava/lang/Number;
7: checkcast #23 // class java/lang/Integer
10: astore_0
11: getstatic #30 // Field java/lang/System.out:Ljava/io/PrintStream;
14: aload_0
15: invokevirtual #36 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
18: return
}
public class GenericTest {
@SuppressWarnings("unchecked")
public static <T extends Number> T test(Object i) {
return (T)i;
}
public static void test() {
Integer i = test(1);
System.out.println(i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment