Difference between NoSuchMethodException and NoSuchMethodError in Java

前端 未结 4 1435
礼貌的吻别
礼貌的吻别 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:20

    NoSuchMethodException is thrown when you try and get a method that doesn't exist with reflection. E.g. by calling Class#getDeclaredMethod(name, parameters) with either the wrong name or parameters.

    NoSuchMethodError is thrown when the virtual machine cannot find the method you are trying to call. This can happen when you compile with one version of a library, and later run the application with another version of the library on the classpath (e.g. an older one that doesn't have the method you're calling)

提交回复
热议问题