Created
July 6, 2012 04:08
-
-
Save cb372/3058010 to your computer and use it in GitHub Desktop.
Grepping for Java casts
This file contains hidden or 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 Foo { | |
public A a = new B(); | |
public B b = (B) a; | |
} | |
class A { | |
} | |
class B extends A { | |
} |
This file contains hidden or 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
$ javap -c Foo | grep checkcast | |
20: checkcast #2 // class B |
This file contains hidden or 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
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