mercredi 3 mai 2023

How to invoke a private static method with parametrized parameter in Java?

I have a method with the following signature private static <T> String getId(T element) and I need to test it.

I have tried to do a stuff like that Method method = MyClass.class.getDeclaredMethod("getId", (Class<?>) any(Object.class));, but it does not work. I got a java.lang.NoSuchMethodException with MyClass.getId(null).

If I well understand, that means that the declared args for the reflection is not well defined.

There is a way to do it?

By advance, no, I can't change the signature of the tested method.





Aucun commentaire:

Enregistrer un commentaire