작은 딸꾹질로 인해 기본적인 질문이 생겼습니다. 나는 다음과 같은 경우에 클래스 동등성을 확인하려는 (학문적 호기심 - instanceof
또는 isinstance
날 직접하지 마십시오) :Java의 클래스 등가
public class staticChild extends staticParent{
....
public static void main(String[] args){
staticChild thisobj=new staticChild();
System.out.println(thisobj.getClass()==staticParent.class);
}
}
이 컴파일 오류를 제공합니다 :이 작업을 수행 무엇
error: incomparable types: Class<CAP#1> and Class<staticParent>
System.out.println(thisobj.getClass()==staticParent.class);
where CAP#1 is a fresh type-variable: CAP#1 extends staticChild from capture of ? extends staticChild
- 평균?
- 유형과 클래스의 차이점은 무엇입니까? (구체적으로이 컨텍스트는 무엇입니까? staticchild의 유형과 클래스는 무엇입니까?)
- 어떻게하면 컴파일 오류를 없앨 수 있습니까?
클래스 >은 일반적이므로 컴파일러는이 비교가 무의미하다는 것을 알 수 있습니다. 두 클래스를 모두 > 클래스로 캐스팅하면 컴파일을 강제 할 수 있어야합니다. –