[英]Javap Exception in thread “main” java.lang.NoSuchMethodError
I have old class which throws this exception. 我有旧类抛出此异常。
com.SomeClass.createEmail(Ljava/lang/String;)Lorg/apache/commons/mail/Email;
After decompiling the old class using Cavaj I have identical source code as in current file. 使用Cavaj对旧类进行反编译后,我具有与当前文件相同的源代码。 So I disassembled the classes and the only difference is in the return type. 所以我反汇编了类,唯一的区别是返回类型。
Old: 旧:
127 invokevirtual com.SomeClass.createEmail(java.lang.String) : org.apache.commons.mail.Email [68]
New: 新:
126 invokestatic com.SomeCalss.createEmail(java.lang.String) : com.NewEmail [68]
NewEmail is extending Email. NewEmail正在扩展电子邮件。 So I guess this return type is the problem even though new return type extends old class. 因此,即使新的返回类型扩展了旧类,我也认为此返回类型是问题所在。 So on JVM machine code level extending is not working :)? 因此,在JVM机器代码级别上扩展不起作用:)?
Each Java method has a signature, which also contains the return type. 每个Java方法都有一个签名,该签名还包含返回类型。
Thus 从而
com.SomeClass1.createEmail(Ljava/lang/String;)Lorg/apache/commons/mail/Email;
and 和
com.SomeClass2.createEmail(Ljava/lang/String;)Lcom/NewEmail;
are different. 是不同的。
It's possible to use inheritance, but this does not change the signature of the invoked method. 可以使用继承,但这不会更改所调用方法的签名。 So if 因此,如果
then the new method is called. 然后调用新方法。
Example: 例:
public class Mail {
}
public class NewMail extends Mail{
}
public class C1 {
public Mail send() {
return new Mail();
}
}
public class C2 extends C1 {
@Override
public NewMail send() {
return new NewMail();
}
}
public class Main {
public static void main(String[] args) {
C1 c = new C2();
Mail m = c.send();
System.out.println(m);
}
}
will print something like 将打印类似
NewMail@64726693
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.