Difference between NoSuchMethodException and NoSuchMethodError in Java

前端 未结 4 1417
礼貌的吻别
礼貌的吻别 2021-02-19 01:47

I can\'t find exact difference between NoSuchMethodException and NoSuchMethodError in Java. Could someone give explanation and example of these two th

4条回答
  •  孤街浪徒
    2021-02-19 02:15

    NoSuchMethodException can be thrown when you're invoking a method through reflection, and the name of the method comes from a variable in your program.

    NoSuchMethodError can be thrown when a compiled Java class does a regular method call to another class and the method doesn't exist. (This usually happens when the caller class was compiled against one version of the class being called, and is being executed together with another version of that class, which no longer has the method.)

提交回复
热议问题