Here you can find a very similar question with a good explanation:
HERE: Why can the final object be modified?
By the way, I started thinking about the reflection mechanism ....
in theory ... I believe that you can get an instance of the owner class .. then get the members of the class, find the current instance and check its final ....
I have not tested it, and I can’t even figure out if this is possible - it’s just an idea (maybe?)
at
public class Final { static final Point p = new Point(); public static void main(String[] args) throws MyImmutableException { p = new Point();
I thought what else you can do ... again it's just !!!!!!!!! PSEUDOCODE !!! I'm not sure if this will work: P
Perhaps someone who knows the annotations will be inspired and make it work. Unfortunately, this week I have no more time. Maybe later I will try to do POC.
public class Final { @Immutable static final Point p = new Point(); public static void main(String[] args) { p = new Point();
Paweł Woźniak Jan 22 '13 at 19:35 2013-01-22 19:35
source share