mercredi 17 février 2021

Java reflection: constructor for primitive int causes: java.lang.NoSuchMethodException: int.

When I try to get the constructor to create an int it throws a: java.lang.NoSuchMethodException: int.<init>(int)

A very simplified version of what I'm trying to do is below:

Class myClass = int.class;
Constructor ctor = myClass.getConstructor(int.class);

I've tried the following as well:

Constructor ctor = myClass.getConstructor(Integer.TYPE);
Constructor ctor = myClass.getConstructor(Integer.class);

to end up with the same exception. What could be causing this?





Aucun commentaire:

Enregistrer un commentaire