可以取出java对象的地址吗?以及java对象某个方法和属性的地址吗?

wtjd 2007-07-26 09:20:40
看下面的代码 ,我想查看对象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的地址,我如何可以取到?
}

}
...全文
529 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wtjd 2007-08-08
  • 打赏
  • 举报
回复
D
骑行的咖啡豆 2007-07-26
  • 打赏
  • 举报
回复
我觉得也只能通过取得hashcode来表示其地址了。
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.)
这个市官方文档上的一段话,也许对你有帮助。
zqrqq 2007-07-26
  • 打赏
  • 举报
回复
没有地址,否则Java的很多安全性就不能得到保证了!
Yanbin_Q 2007-07-26
  • 打赏
  • 举报
回复
java里没有这些概念,他并不像C++程序,什么都有个地址,有方法指针就可以调用方法。
KingNE 2007-07-26
  • 打赏
  • 举报
回复
没有地址,否则Java的很多安全性就不能得到保证了!
Anndyang 2007-07-26
  • 打赏
  • 举报
回复
其实对于java来说,根本没必要考虑这些问题!
我也是菜鸟级的,但是我认为这可能跟JVM的实现有关吧,同一段程序在不同的JVM下可能分配的地址也会不同!比如在windows平台和Linux平台可能就不一样!
willishz 2007-07-26
  • 打赏
  • 举报
回复
一个CLASS的多个实例,地址是不一样的吧.
wtjd 2007-07-26
  • 打赏
  • 举报
回复
那一个CLASS的多个实例,函数地址是不是一样的呢?

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧