1.Java String can be changed.
It has always been assumed that the value of string types in Java cannot be modified, mainly because the string is final and there is no set method for setting the value. However, the value can be changed by reflection mechanism.
Example 1
public class Test {public
static void Main (string[] args) throws Exception {
String s= "0123456789";
System.out.println ("Before Change: s=" + s);
Field f = S.getclass (). Getdeclaredfield ("value");
F.setaccessible (true);
F.set (S, New char[]{' A ', ' B ', ' C '});
System.out.println ("After change: s=" + s);
}
Example 1 results:
Before change: s=0123456789
change: s=abc
Example 1 reasons
There is a private final char value[member variable in the String class, and the value of the string class is stored in this value property. You can change this value by reflection to achieve the purpose of changing the string class value. By the same token, in this way