Public class Test {
Public static void main (String [] args) {
List AList=new ArrayList<> (a);
A. A=new A ();
System. The out. Println (aList instanceof A);//compile can pass?
System. Out.println (aList instanceof ListSystem. Out.println (aList instanceof ListSystem. Out.println (a instanceof List<? & gt;);//compile can pass?
System. The out. Println (a instanceof List);//compile can pass?
//A and the List is not the same inheritance tree, why to compile?
}
}
Class A {
}
Class B {
}
1. A and the List without inheritance, why compilation can pass?
2. AList instanceof List Why don't compiled by?
CodePudding user response:
https://www.cnblogs.com/lzq198754/p/5780426.htmlCompile without reason, generic erasure mechanism, so the error
Compiled by the reason, why don't you through, it's not assert, won't produce an error, true or false, the only result instanceof judge is equivalent to only. The equals realized in the end
CodePudding user response:
List AList=new ArrayList<> (a);A. A=new A ();
B B=new B ();
System. The out. Println (instanceof b A);//A and B without inheritance, so compiled by not
System. The out. Println (aList instanceof A);//the List and A also does not have inheritance relationship, why can pass?
CodePudding user response: