Potential obfuscation
May 31st, 2004 by HenI like to keep track of a list of nasty things you can do to a Java source file. Things like putting $ at the front of all your variable names etc.
Anyway, realised another one today; which hides under all of our noses.
It’s easy to get into the habit of always coding public classes, so easy to fall into the trap of thinking that the Java class ‘XXX’ must be in a file named ‘XXX.java’.
This is true if ‘XXX’ is public, but not if it’s package level. If the class(es) in a Java source file (you did know you can put more than one class in a file right?) are all package level, then you can name the file anything you want.
OddsAndSods.java:class Web {
int i = 0;
}
class Log {
int j = 0;
}
Of course, from this you get Web.class and Log.class.
