With the introduction of Reflection API we now can freely access any private fields as we wish.
For example :
Field f = obj.getClass().getDeclaredField("stuffIWant");
So now, what if we eliminate all modifier and set a common rule for Java developers to not access field directly but via getter/setter ? Obviously one can violate the rule but even if we have modifiers, we can still access them without using modifiers.
Aucun commentaire:
Enregistrer un commentaire