< Previous
Attention George Moffitt >

[Comments] (1) Finally!: Hack bytecode to subclass allegedly "final" Java classes. Combine with Multiple inheritance for Java and really piss off the Java designers. Link found at Deft Code.

Filed under:

Comments:

Posted by steve minutillo at Wed Jul 14 2004 15:05

As of Java 1.5, oh sorry, I meant Java 5, you can even modify private, final fields through reflection!

Also Java 1.5 includes an annotation processing tool, confusingly called "apt". It parses your code, looks for, and processes annotations. Annotations are allowed to generate more Java code, which can be written out to disk, and also have access to the entire source code for the file that they occur in, so that annotations can do things like auto-magically generate EJB home/remote interfaces and other types of boring boilerplate code. Once all the annotations are expanded, apt calls javac to compile the original classes as well as any generated ones. At JavaOne, after this was descibed, somebody in the audience stood up and said with a smirk "So... can I have a class, say in a file called Devious.java, which contains annotations that cause a new file to be written out, also called Devious.java?"

At this point the Java guys all flew into a rage! "NO! YOU CANNOT USE APT AS A PREPROCESSOR!" They said they put code in apt specifically to disallow these sort of hijinks. They claimed it halts processing and sends email to Graham Hamilton, one of the Java language architects, informing him of what you tried to do. They said that this is "much, much worse than a core dump".


A recurring theme with those guys is how much better Java is than C++. They constantly make fun of the fact that C++ has, COMPLETELY BY ACCIDENT, a Turing complete language in the template system. They said the C++ community discovered their so-called "template metaprogramming", and instead of recoiling in horror, they shouted, a la Dr. Frankenstein, "IT'S ALIVE!" and immdiately put it to work. Of course it's only a matter of time before it turns on them and kills them.


[Main] [Edit]

Unless otherwise noted, all content licensed by Leonard Richardson
under a Creative Commons License.