try
{
String str = "yyg";
System.out.println("str=" + str + ", 唯一性hash值=" + System.identityHashCode(str));
Class stringClass = str.getClass();
//获取String类中的value属性
Field field = stringClass.getDeclaredField("value");
//设置私有成员的可访问性,进行暴力反射
field.setAccessible(true);
//获取value数组中的内容
char[] value = (char[]) field.get(str);
System.out.println("value=" + Arrays.toString(value));
value[1] = 'z';
System.out.println("str=" + str + ", 唯一性hash值=" + System.identityHashCode(str));
}
catch(NoSuchFieldException | IllegalAccessException e)
{
e.printStackTrace();
}