Is it possible in java to create ‘blank’ instance of class without no-arg constructor using reflection?

With standard reflection, no, but there is a library that can do it for you: objenesis.

It’s specifically designed to instantiate classes without default constructors, and it’s used by other serialization libraries like xstream.

Note: the constructor might not be called in these cases (but that’s presumably what you want).

Leave a Comment