Java CGLib:找不到重写方法
我有密码:Java CGLib:找不到重写方法,java,exception,cglib,Java,Exception,Cglib,我有密码: 1 abstract class A { 2 public abstract <T> T getId(); 3 } 4 class B extend A { 5 public Long getId() { 6 return Long.valueOf(1); 7 } 8 } 9 public class Main { 10 public static void main(String [] args) { 11
1 abstract class A {
2 public abstract <T> T getId();
3 }
4 class B extend A {
5 public Long getId() {
6 return Long.valueOf(1);
7 }
8 }
9 public class Main {
10 public static void main(String [] args) {
11 FastClass fast = FastClass.create(B.class);
12 FastMethod fastMethod = fast.getMethod("getId", null);
13 try {
14 final B b = new B();
15 Long value = (Long) fastMethod.invoke(b, null);
16 } catch (Exception e) {//
17 e.printStackTrace();
18 }
19 }
20 }
1抽象类A{
2公开摘要T getId();
3 }
4 B级延伸至A级{
5公共长getId(){
6返回长。值为(1);
7 }
8 }
9公共课主课{
10公共静态void main(字符串[]args){
11 FastClass fast=FastClass.create(B.class);
12 FastMethod FastMethod=fast.getMethod(“getId”,null);
13试{
14最终B=新B();
15 Long value=(Long)fastMethod.invoke(b,null);
16}捕获(例外e){//
17 e.printStackTrace();
18 }
19 }
20 }
并在第12行抛出IllegalArgumentException:找不到方法public java.lang.Long B.getId()
如何获取实例FastMethod类并执行FastMethod.invoke()?我必须为类A获取实例FastClass,并从中获取实例FastMethod,但使用参数实例类B调用实例FastMethod 此代码工作正常:
1 abstract class A {
2 public abstract <T> T getId();
3 }
4 class B extend A {
5 public Long getId() {
6 return Long.valueOf(1);
7 }
8 }
9 public class Main {
10 public static void main(String [] args) {
11 FastClass fast = FastClass.create(A.class); // changed, was FastClass.create(B.class)
12 FastMethod fastMethod = fast.getMethod("getId", null);
13 try {
14 final B b = new B();
15 Long value = (Long) fastMethod.invoke(b, null);
16 } catch (Exception e) {
17 e.printStackTrace();
18 }
19 }
20 }
1抽象类A{
2公开摘要T getId();
3 }
4 B级延伸至A级{
5公共长getId(){
6返回长。值为(1);
7 }
8 }
9公共课主课{
10公共静态void main(字符串[]args){
11 FastClass fast=FastClass.create(A.class);//已更改,为FastClass.create(B.class)
12 FastMethod FastMethod=fast.getMethod(“getId”,null);
13试{
14最终B=新B();
15 Long value=(Long)fastMethod.invoke(b,null);
16}捕获(例外e){
17 e.printStackTrace();
18 }
19 }
20 }