Changing private final fields via reflection

前端 未结 4 1041
鱼传尺愫
鱼传尺愫 2020-11-28 07:20
class WithPrivateFinalField {
    private final String s = \"I’m totally safe\";
    public String toString() {
        return \"s = \" + s;
    }
}
WithPrivateFinal         


        
4条回答
  •  余生分开走
    2020-11-28 07:57

    Being final, the compiler expected the value not to change, so it probably hardcoded the string directly into your toString method.

提交回复
热议问题