두 개의 메소드를 오버라이드하려는 수퍼 클래스가 있습니다. 여기에 내 코드입니다 : 내가 어떤 생성자가확장 수퍼 클래스와 ClassCastException
public class MyCustomClass extends SomeSuperClass {
protected MyCustomClass(params) {
super(params);
}
@Override
public void method1() {
super.method1();
/* here goes my code */
}
@Override
public void method2() {
super.method2();
/* here goes my another code */
}
, 매개 변수로 SomeSuperClass 객체를 전달하고 난 다음에 무엇을 :
MyCustomClass object;
/* now i have object of type SomeSuperClass,
but with my own method1() and method2() */
object = (MyCustomClass) MyCustomClass.item(blahblah);
/* eclipse suggests casting, because MyCustomClass.item()
constructor still returns SomeSuperClass object */
otherobject = OtherConstructor.object(object);
//OtherConstructor passes SomeSuperClass object
잘 될 것 같다,하지만 난 자바를 얻고있다. 실행 중 SomeSuperClass에서의 lang.ClassCastException
SomeSuperClassObject를 만들면 재정의 된 메서드가 손실됩니다.
캐스팅을 사용하면 eclipse에서 오류가 발생하지 않아도 응용 프로그램이 충돌합니다. 즉, 어떻게 내 자신의 메서드를 사용하여 SomeSuperClass를 재정의 할 수 있고 OtherConstructor와 함께 사용할 SomeSuperClass 개체를 얻을 수 있습니까? 중요한 경우이 코드는 android app 용입니다.
'MyCustomClass.item'의 코드는 무엇입니까? – Powerlord
그것은 오버라이드되지 않으므로 슈퍼 클래스 메서드 – artemy
을 사용하여 페르시안주의를 사용하기 만하면됩니다. MyCustomClass.item()은 "생성자"가 아니며 또한 "OtherConstructor.object()"도 아닙니다 (실제로 이클립스 코드 도우미에 따르면) ' –