I am trying to write a java program which can create an instance of various objects. But I don't know these objects, so they need to be created dynamically. This works fine with reflection but I've to problems:
I wrote an utility class which contains a Map<Class, Object>
. This map contains all primitive types e.g.
dummyValueMap.put(int.class, Integer.MIN_VALUE);
So I can query a dummy object for int to use this value in a constructor of the object which I don't know at compile time, to create a instance. Now my problem is that I need dummy values for the primitive types which can be used by all constructors, so Integer.MIN_VALUE
or MAX_VALUE
is not a good idea. Does anyone know of better values for the types or is there a special framework?
What can I do if the constructor parameter is an Interface? How do I get an implementation of this interface dynamically?