Reputation: 51
now exists a class below:
class A{ private A(HashMap map){ } }
how can I get the constructor that the parameters are generics with reflection?
EDIT : Question edited.
Upvotes: 0
Views: 513
Reputation: 533880
You can't have templates in Java. You can have Generics and you can get that information from the Constructor.
Constructor aConstructor = A.class.getConstructors()[0];
Class[] parameterTypes = aConstructor.getParameterTypes();
System.out.println(Arrays.toString(parameterTypes)); // prints [java.util.HashMap]
BTW: Is there any reason it has to be a HashMap and not a Map?
Upvotes: 1