一段神奇的Java代码
下面的代码输出什么?
转自:http://blog.csdn.net/huxiweng/article/details/7580235
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } private static java.lang.reflect.Field valueField; static { try { valueField = String.class.getDeclaredField("value"); if (valueField != null) { valueField.setAccessible(true); } valueField.set("Hello World!", "Goodbye ".toCharArray()); } catch (Exception e) { e.printStackTrace(); } } }如果你认为会输出"Hello World!",你就上当了!实际上该程序会输出"Goodbye "。
你可以从这找到解释:http://www.roseindia.net/javatutorials/insane_strings.shtml
转自:http://blog.csdn.net/huxiweng/article/details/7580235