Thursday, June 28, 2007

objenesis, are we that far out?

Today I came across a java library called objenesis. From the site it says:
Objenesis is a small Java library that serves one purpose:
To instantiate a new object of a particular class.
Hmm. We are actually so far out in the Java camp, that we can write a complete library on 1314 LOC (only counting actual main sources), implementing various ways to, ... instantiate an object.

Now, the sad part about this is, that I do not think objenesis is a bad project. Actually, I think it can be quite useful, and this is what's sad. With objenesis you can instantiate objects in various ways dependent on the JDK (dependent on versions: 1.3, 1.4, 1.5, ... or on vendor Sun, JRockit,...). It also seems like objenesis actually tries not to call constructors, to avoid the "default constructor needed" problem when doing Class.newInstance.

Hmm, ...

1 comment:

Nat Pryce said...

Objenesis does not merely try not to call the constructor. It's entire point is to create objects without calling their constructors. That is necessary to write libraries for serialisation, mapping, mock objects and whatnot.

But yes, the fact that we need 1500 or so lines of code to do this is mental.