本帖最后由 adfhjk 于 2012-07-25 15:51:37 编辑

解决方案 »

  1.   

    1. 是的
    2. 是的。对于e="qwr";在方法区里有一块运行时常量池,存放各个类的常量池和String.intern产生的常量。我的理解是会从运行时常量池中检索"qwr"是否存在。3. new一个对象,在堆中分配内存空间存储对象实例数据(对象中各个实例数据),如果是primitive type直接分配空间存储值,对象就是存储引用了。
      

  2.   

    String e="qwe"; 是先在常量池中找看有没有,有则直接指向
    如没有 则需要创建的?
    我是这样理解不知对不?
      

  3.   

    后来网上搜了一些,好像在heap的永生代有个interned table用于存储已经出现过的table,而检索好像是在这个table里检索的,那么这个table是全局的。
    其次,你的意思是运行时常量池时和各个类的常量池不同?它是把各个类的东西放在一起,变成了global的?要不A类检索字符串的时候就只能检索自己 的那部分了。不知道我的理解对不对。
    另外,对于string变量的引用是实例as直接引用heap中的string c的实例吗?
      

  4.   

    In JDK 7, interned strings are no longer allocated in the permanent generation of the Java heap, but are instead allocated in the main part of the Java heap (known as the young and old generations), along with the other objects created by the application. This change will result in more data residing in the main Java heap, and less data in the permanent generation, and thus may require heap sizes to be adjusted. Most applications will see only relatively small differences in heap usage due to this change, but larger applications that load many classes or make heavy use of the String.intern() method will see more significant differences.
      

  5.   

     可以这么理解,常量池中有CONSTANT_Integer_info,CONSTANT_Float_info和CONSTANT_String_info等等。。这个可以去查。所有的常量都放这里面,而且只有一份。对象使用引用来获取值。
     具体可以查常量池技术。
      

  6.   

    http://www.infoq.com/cn/articles/jvm-hotspot