Abstract callbacks in java reflection methods
•
Java
I have a class in jar and I want to call a method However, this method has parameters of abstract class, which is the internal method of class in jar Abstractclassa is a hidden class This is the code:
public class A{
private invokeThisMethod(AbstractClassA object){
}
public abstract class AbstractClassA {
public void update(int remaining){}
}
}
public class myClass{
//using Reflection get object of class A
objectOfClassAusingReflection.inovke("invokeThisMethod",params)
}
The question here is how to create a concrete implementation of abstractclassa to pass in the invoke method and get the update method callback?
Solution
Such things should work:
AbstractClassA a = new AbstractClassA() {
public void update(int remaining) {... do something...}
};
objectOfClassAusingReflection.inovke("invokeThisMethod",a);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
