Be careful JVM
来源:互联网 发布:php cookie使用 编辑:程序博客网 时间:2024/05/12 15:45
Long time no to come here , for the company cut my Internet .
Be careful the JVM compile the java file , especially, for the static final field . Here is an example .
B.java
package com.liangbinny.test;
public class B {
public static final String T = "A+B";
}
A.java:
package com.liangbinny.test;
public class A {
public static void main(String[] args) {
System.out.println(B.T);
}
}
After compiled A.java , and we can get A.class file ,,but if we decompile A.class , we will find that
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov Date: 2013-5-14 20:56:25
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: A.java
package com.liangbinny.test;
import java.io.PrintStream;
public class A
{
public A()
{
}
public static void main(String args[])
{
System.out.println("A+B");
}
}
Anything different with A.java ?
Yes , we never see System.out.println(B.T); code , but we see System.out.println("A+B"); .
So , if a lib contain A.class and B.class , we change B.java , we not only need replace B.class file , we need replace A.class too.
We should be careful JVM compile the java code .
For more examples ,
How many String object create about this code ?
String s = "a"+"b+"c";
the answer is only one . as "abc"
For more examples ,
String a = "a";
String s = a +"b"+"c";
the answer is 4 , as "a", "b","c" , and "abc"
how about this ?
String a = "a";
String s = "b"+"c"+a;
the answer is 3, as "a","bc","abc"
That's all .
- Be careful JVM
- be careful
- Be Careful With Transient Data
- Be Careful With Transient Data
- Be Careful With Transient Data
- Be Careful With Transient Data
- Be Careful With Transient Data
- Be careful about the angles
- Be Careful With Transient Data
- Be careful while using autoremove! !
- Be careful to use iterator - vector.begin()
- Be Careful With Static Stuff on AsyncTask
- Xaml - Be careful of binding with ContextMenu
- Be careful when Android up merge
- Be careful about the "id" property
- 《coraline》观后感:Be careful what you wish for
- Be careful of static field when unit testing!
- JS advice: Be careful the difference between Undefined and ‘ ’
- 目前比较流行的Python科学计算发行版
- Motorola XOOM平板电脑(wingray)刷机方法
- 我的CSDN情结--工作一年总结
- C++ namespace
- Spring系列之四——Spring IOC依赖注入
- Be careful JVM
- Linux内核中断内幕
- wince7.0文件系统挂载注册表设置
- linux学习之linux百问3,sed了解
- 由余弦定理,求两个线段的夹角
- [C++]VS跨项目调用全局函数
- HDU 2045(递推)
- HDU2689:Sort it
- POJ3921 && HDU 2485 Destroying the bus stations(最大流 or 费用流)