2011-12-21 2 views
-4

클래스에서 익명 메소드를 실행하는 방법.Java Generic on Class

object Form = SomeRandomForm 
Form.Save() // anonymously no need to inherit 

이 가능 VB에서

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 

같다 : 예를 들어

,

나는

내가 어딘가에서 개체를 받고
Class A { 
    void Save(){ 
    //do something 
    } 
} 


Class B { 
     void Save(){ 
     //do something 
     } 
    } 

클래스를 가지고 자바에서?

답변

3

나는 그것이 무슨 뜻 (일부 코드가 도움이 될 수 있습니다)하는 것이 정확히 무엇인지 모르겠지만, 기본적으로 당신은 단지 인터페이스의 제네릭과 패널의 구체적인 유형 정의 :

interface MyInterface<T> { ... } 

class StringPanel extends JPanel implements MyInterface<String> { ... } 

나머지를 너에게 달렸다.