Improve the creation of instance objects

Volker Simonis volker.simonis at gmail.com
Fri Jan 2 16:32:09 UTC 2015


Hi Alexey,

thanks for creating the JOL-tools - they are really nice.

I've played around with them and I want to propose the following small
patch which improves the creation of instance objects.

Currently you are using Class.newInstane() but this will fail if the
default constructor is not accessible.
I'd like to propose the usage of Class.getDeclaredConstructor() to get
the default constructor. If it is not accessible we can set it to
'true' with ctor.setAccessible(true). Afterwards we can simply call
ctor.newInstance().

What do you think? With these small changes I could get some better
results when calling MainObject{Internals, Externals, Footprint} on
some classes which only had private constructors.

S novem godom,
Volker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jol.patch
Type: text/x-patch
Size: 3191 bytes
Desc: not available
URL: <http://mail.openjdk.java.net/pipermail/jol-dev/attachments/20150102/4ad38354/jol.patch>


More information about the jol-dev mailing list