Skip to content

Instantly share code, notes, and snippets.

@cb372
Created July 6, 2012 04:08
Show Gist options
  • Save cb372/3058010 to your computer and use it in GitHub Desktop.
Save cb372/3058010 to your computer and use it in GitHub Desktop.
Grepping for Java casts
public class Foo {
public A a = new B();
public B b = (B) a;
}
class A {
}
class B extends A {
}
$ javap -c Foo | grep checkcast
20: checkcast #2 // class B
Compiled from "Foo.java"
public class Foo {
public A a;
public B b;
public Foo();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: aload_0
5: new #2 // class B
8: dup
9: invokespecial #3 // Method B."<init>":()V
12: putfield #4 // Field a:LA;
15: aload_0
16: aload_0
17: getfield #4 // Field a:LA;
20: checkcast #2 // class B
23: putfield #5 // Field b:LB;
26: return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment