I think this is possible, because each rule has its own exception, each best practice can be redefined in certain cases.
For example, I often expose public static finite data items as public (for example, constants). I do not think this is harmful.
I will point out that this situation is also true in languages other than Java: C ++, C #, etc.
Languages do not always have to protect us from ourselves.
In Olya’s example, what harm do I write like this?
public class Point { public final int x; public final int y; public Point(int p, int q) { this.x = p; this.y = q; } }
It is immutable and stream-safe. Data members may be publicly available, but you cannot harm them.
Also, it is a dirty little secret that "private" is not really private in Java. You can always use reflection to get around it.
So relax. It's not so bad.
duffymo Dec 09 '11 at 12:48 2011-12-09 12:48
source share