看下面的代码 ,我想查看对象x的地址,以及x的方法getA,getB,以及属性a,b的地址,我如何可以取到?
package test;
public class AClass {
public String a;
public Object b;
public AClass(){
this.a= "tt";//与 new String ("ttt");结果完全不一样。
this.b= new Object();
}
public String getA(){return a;}
public Object getB(){return b;}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
AClass x = new AClass();
//我想查看对象x的地址,以及x的方法getA,getB,以及属性a,b的地址,我如何可以取到?
}
}
package test;
public class AClass {
public String a;
public Object b;
public AClass(){
this.a= "tt";//与 new String ("ttt");结果完全不一样。
this.b= new Object();
}
public String getA(){return a;}
public Object getB(){return b;}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
AClass x = new AClass();
//我想查看对象x的地址,以及x的方法getA,getB,以及属性a,b的地址,我如何可以取到?
}
}
As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)
这个市官方文档上的一段话,也许对你有帮助。
我也是菜鸟级的,但是我认为这可能跟JVM的实现有关吧,同一段程序在不同的JVM下可能分配的地址也会不同!比如在windows平台和Linux平台可能就不一样!