How do I invoke a private static method using reflection (Java)?

前端 未结 5 444
[愿得一人]
[愿得一人] 2020-11-29 03:32

I would like to invoke a private static method. I have its name. I\'ve heard it can be done using Java reflection mechanism. How can I do it?

EDIT:

5条回答
  •  感动是毒
    2020-11-29 04:00

    No, you can't say Map.class. This is because of type erasure. At runtime, there's no such thing.

    Luckily, you can say just plain old Map.class. It's all the same at runtime.

    If the warnings bother you, search for other questions related to generics and type erasure, there's a wealth of information on the subject here.

提交回复
热议问题