Is hash code of java.lang.String really cached?
问题 String s1 = "String1"; System.out.println(s1.hashCode()); // return an integer i1 Field field = String.class.getDeclaredField("value"); field.setAccessible(true); char[] value = (char[])field.get(s1); value[0] = 'J'; value[1] = 'a'; value[2] = 'v'; value[3] = 'a'; value[4] = '1'; System.out.println(s1.hashCode()); // return same value of integer i1 Here even after I changed the characters with the help of reflection, same hash code value is mainatained. Is there anything I need to know here?