Skip to content

Detecting method calls where receiver is of given type #1122

Answered by hankem
knutwannheden asked this question in Q&A
Discussion options

You must be logged in to vote

I fear that the byte code might not contain the information that Object#equals(Object) was called on a Foo:
In the example

class Foo {
   boolean eq() {
     Foo foo = new Foo();
     return foo.equals(new Object());
   }
}

the method eq is compiled to the byte code (cf. javap -c -p -v Foo.class):

         0: new           #7                  // class Foo
         3: dup
         4: invokespecial #9                  // Method "<init>":()V
         7: astore_1
         8: aload_1
         9: new           #2                  // class java/lang/Object
        12: dup
        13: invokespecial #1                  // Method java/lang/Object."<init>":()V
        16: invokevirtual #10          …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@knutwannheden
Comment options

Answer selected by knutwannheden
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants