Xxx.class = a hack
September 30th, 2003 by HenI remember a friend back in the UK who is big into looking at class files complaining that .class files were a big hack. Now I understand why:
list.add( Object.class );
is also known as:
list.add(class$java$lang$Object == null
? class$java$lang$Object = class$(”java.lang.Object”)
: class$java$lang$Object);
plus a hidden method and variable:
/*synthetic*/ static Class class$java$lang$Object;
/*synthetic*/ static Class class$(String x0) {
Class var_class;
try {
var_class = Class.forName(x0);
} catch (ClassNotFoundException x1) {
throw new NoClassDefFoundError(x1.getMessage());
}
return var_class;
}

October 1st, 2003 at 12:07 am
I am not sure this is a hack considering “synthetic” usage has decent documentation in VM Spec.
October 1st, 2003 at 8:01 am
There is a fine line between syntactic sugar and a hack. Xxx.class is syntactic sugar, along with all the new “language featuers” in 1.5. Under the covers it may look ugly but when it’s all sugared up who cares if you are eating flakes made of sub-standard corn not fit for the produce aisle of the super market?
It’s not you are writing code using reflection to invoke a jdk 1.4 method so the class will compile in a 1.1 java compiler. Now _that’s_ a hack!
October 8th, 2003 at 5:38 am
class A {
class B { }
static void foo() {
A _this = new A();
B b = _this.new B();
}
}
Now thats a hack