SCJP5.0, SCJA
All code in my posts, unless a source is explicitly mentioned, is my own.
SCJP5.0, SCJA
Notice that List<?> is exactly the same as List<? extends Object>.
SCJP 6
Morteza Manavi-Parast wrote:
Notice that List<?> is exactly the same as List<? extends Object>.
Ruben,
While I’m generally agree with your explanation for this question, but I’m afraid that your last line which I quote above is Incorrect.
The upper bound wildcard parameterized type (<? extends object>) are equivalent but they are NOT “exactly the same”
Here is a case that you can see the difference:
Output:
C:\java\src>javac -Xlint GenericsTest.java
GenericsTest.java:19: warning: [unchecked] unchecked conversion
found : java.util.List
required: java.util.List<? extends java.lang.Object>
extObjList = rawList; // !****Unchecked Conversion warning****!
^
1 warning
So, Considering these cases we can say they are essentially equivalent, but they are NOT exactly the same.
All code in my posts, unless a source is explicitly mentioned, is my own.
“To me, if you can assign reference a to reference b and also assign reference b to reference a (and both of this without using the casting operator,) that means that their types are exactly the same.”
SCJP 6
All code in my posts, unless a source is explicitly mentioned, is my own.
SCJP 6
All code in my posts, unless a source is explicitly mentioned, is my own.
SCJP 6
All code in my posts, unless a source is explicitly mentioned, is my own.
All code in my posts, unless a source is explicitly mentioned, is my own.
SCJP 6
Morteza Manavi-Parast wrote:Ok, I agree to go through questions one by one, but before we start, can you describe the following errors with your logic?
Object obj ;
boolean isExtList = obj instanceof List<? extends Object>; // Compiler Error: "illegal generic type for instanceof"
boolean isExtList = obj instanceof List<?>; // Compiles fine!
List<? extends Object>[] list3 = {Arrays.asList("1", "2")}; // Compile Error: "generic array creation"
List<?>[] list4 = {Arrays.asList("1", "2")}; // Compiles Fine!
All code in my posts, unless a source is explicitly mentioned, is my own.
SCJP 6
All code in my posts, unless a source is explicitly mentioned, is my own.