Getting java.lang.NullPointerException when calling Method.invoke

前端 未结 4 1238
耶瑟儿~
耶瑟儿~ 2021-02-19 11:17

I\'m following this tutorial on Java annotaitons and implemented the Test annotation as shown there. But when running the code I get the following output.

java.l         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-19 11:47

    The Method#invoke has the answer to your question:

    public Object invoke(Object obj,
                Object... args)
                  throws IllegalAccessException,
                         IllegalArgumentException,
                         InvocationTargetException
    

    Throws: NullPointerException - if the specified object is null and the method is an instance method.

提交回复
热议问题