update INVOKEVIRTUAL

This commit is contained in:
wangxiang
2023-07-20 15:44:06 +08:00
parent 51623e505c
commit 0c478baa17
5 changed files with 10 additions and 26 deletions

View File

@@ -87,9 +87,10 @@ public class INVOKEVIRTUAL extends Instruction {
javaClass = klass.getJavaClass();
}
// 按照继承关系从下往上找实现的方法 (实现多态)
org.apache.bcel.classfile.Method method = getMethod(javaClass, methodSignature, methodName);
if (method == null) {
throw new NoSuchMethodException();
throw new AbstractMethodError();
}
KlassMethod klassMethod = new KlassMethod(klass, method);
JavaExecutionEngine.callMethod(frame, klassMethod);

View File

@@ -1,7 +0,0 @@
package haidnor.jvm.test.clazz;
public class Baby {
public void eat() {
System.out.println("婴儿吃奶粉");
}
}

View File

@@ -0,0 +1,7 @@
package haidnor.jvm.test.clazz;
public class Human {
public void eat() {
System.out.println("人类吃饭");
}
}

View File

@@ -1,7 +0,0 @@
package haidnor.jvm.test.clazz;
public interface Person {
void eat();
}

View File

@@ -1,15 +1,5 @@
package haidnor.jvm.test.clazz;
public class Student extends Baby{
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public class Student extends Human {
}