effect of changing String using reflection

后端 未结 7 603
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 17:54

As we all know, String is immutable in java. however, one can change it using reflection, by getting the Field and setting access level. (I know it is unadvised, I am not pl

7条回答
  •  清歌不尽
    2020-12-03 18:03

    The private fields in the String class are the char[], the offset and length. Changing any of these should not have any adverse effect on any other object. But if you can somehow change the contents of the char[], then you could probably see some surprising side effects.

提交回复
热议问题