日期:2014-05-20  浏览次数:20571 次

常量池解析中的直接引用是什么?
常量池解析把符号引用转为直接引用,直接引用到底是什么

------解决方案--------------------
物理地址

  常量池仅仅是一个引用和描述符的集合,并不接受任何赋值操作。
  
  所有对象的创建,方法和类变量的调用均要从常量池中获取信息,但实例变量的调用从堆里获得。(猜想)
  
  符号引用是由虚拟机解析后得到具体的地址来使用。
  
  常量池解析就是将常量池中的符号引用替换成直接引用。
  
  当要使用某个类的方法或字段时,首先从常量池中找到该方法或字段的符号引用,然后进行解析,找到其物理地址。
  
  把代码中出现的各种符号引用,类与类的联系,进行常量池解析,叫做动态连接。

或者说是存放在内存中的位置

------解决方案--------------------
探讨
那,就像这样:

char b='a';

这就是在内存中的常量池中一个字符,它的引用名为b,转换为的Ascll码为:97

这里说的97就是字符a在常量池中的直接引用。

------解决方案--------------------
你是不是说String.intern()方法:
Returns a canonical representation for the string object. 
A pool of strings, initially empty, is maintained privately by the class String. 

When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned. 

It follows that for any two strings s and t, s.intern() == t.intern() is true if and only if s.equals(t) is true. 

这个是由java虚拟机实现的