views:

86

answers:

3

In Java, one can create instances of a class without actually calling a declared constructor by retrieving one via sun.reflect.ReflectionFactor.newConstructorForSerialization().

As far as I know, this special constructor is called "munged". Where does this term come from? I could not find it in any dictionary.

+1  A: 

I believe it's used as in the following sense, because you are somehow bypassing/faking the normal object creation cycle, by skipping the constructor:

(computing) modify or fake an email (or other internet) address so it cannot be automatically harvested, esp. to avoid spam bots

(computing) change a file; make irrevocable changes, destroy, obfuscate

Both definitions are from Princeton's WordNet.

JG
A: 

From the wiktionary:

To transform data in an undefined or unexplained manner.

The constructor for deserialisation does not [necessarily] call the super class constructor and is not part of the original class. From a JVM spec perspective, it is illegal - a munged version of a legal constructor.

Tom Hawtin - tackline
A: 

Additionally, classes from the package sun.* should not be used directly as they may not be available on other JDK implementations (so this "constructor" may be undefined with another JDK).

Zelos
You could use objenesis: http://code.google.com/p/objenesis/There are situations where you have to bypass constructors: * Serialization, Remoting and Persistence - Objects need to be instantiated and restored to a specific state, without invoking code. * Proxies, AOP Libraries and Mock Objects - Classes can be subclassed without needing to worry about the super() constructor. * Container Frameworks - Objects can be dynamically instantatiated in non-standard ways.(Taken from the website above.)
Martin Burger