Community

How can get the initial member field value?

reply from Stuart Douglas in Javassist - View the full discussion

This stuff is set in the constructor, so some of it can be extracted, probably not it the format you want though.

 

For integer fields the bytecode code that gets generated would look something like:

 

ALOAD_0 //put the this pointer on the stack

ICONST_2 //put the integer constant 2 on the stack

PUTFIELD com/mydomain/Point.x //set the field value.

 

The hashmap field would be slightly more complex:

 

ALOAD_0 //put the this pointer on the stack

ANEW java/util/HashMap //create the hashmap instance

DUP //duplicate it so it is still on the stack after the constructor call

INVOKESPECIAL java/util/HashMap.<init> //call the constructor

PUTFIELD com/mydomain/Point.hashMap //set the field value.

 

 

To actually extract this information you would need to write some kind of bytecode analyser, and even then there would be cases that it could not handle correctly, as you would also need some kind of dissasembler to go back from the bytecode into java.

Reply to this message by going to Community

Start a new discussion in Javassist at Community