如何从类运行匿名方法。
例如,
我有一堂课
Class A {
void Save(){
//do something
}
}
Class B {
void Save(){
//do something
}
}
当我从某个地方获取对象时:
Object something = (could be A or B both because object can accept anything.)
something.Save() //doesn't work. To solve this I could use inheritance(abstract class or Interface) but if I want to do it anonymously
就像在 VB 中一样
object Form = SomeRandomForm
Form.Save() // anonymously no need to inherit
在java中可以吗?