네, 당신은 그것을 할 수 있습니다 :
private InterfaceMap m = new OurSheetMatrix();
은 OK입니다.
public void doSomething(InterfaceMap iamp) {
//Do something with an InterfaceMap.
//I don't know (or care) exactly what class it is,
//so long as it implements InterfaceMap
}
을하지만 더 구체적인 뭔가가있는 경우 : 당신은 또한 방법에 주위에 당신의 인터페이스에 대한 참조를 전달할 수 있습니다
InterfaceMap imap = new OurSheetMatrix(); //this is OK
doSomethingElse(imap); //But this? NO! can't do this!
위에게 :
public void doSomethingElse(OurSheetMatrix matrix) {}
그것은 다음과 같이 호출 할 수 없습니다 doSomethingElse
은 doSomethingElse
이 OurSheetMatrix
을 원하기 때문에 컴파일되지 않습니다. 우리는 실제로 그것이 OurSheetMatrix
이라는 것을 알지만, 그 방법은 알지 못합니다.
모든 OneSheetMatrix
객체도 InterfaceMap
의, 그러나 InterfaceMap
의 반드시OneSheetMatrix
개체 수 없습니다, 따라서 doSomethingElse
에 대한 호출이 유효하지 않습니다 - InterfaceMap
를 구현하는 다른 클래스가있을 수 있습니다.
시도하지 않았습니까? – home