List<?> x1= new ArrayList<>();
var x2= new ArrayList<>();
Here x1 is of type List and x2 of type ArrayList
In the book it is mentioned that, we can only assign x2 to a List<Object>.
This might be a potential error as x2 cannot accept List<Object>. Please confirm (x1 can be assigned though)
I didn't find this exact example anywhere in the paper text for the 816.
I believe you slightly modified the example from right near the end of "Using the Diamond Operator" just before "Using Lists, Sets, Maps, and Queues"?
In general, you can not assign a reference variable to a more specific one without an explicit cast.
For example, you can not say:
Integer IOriginal = Integer.valueOf( 5 ); // fine so far
Number N = IOriginal; // still good
Integer I = N; // we know this is good but the compiler does not.
jshell> Integer I = N;
| incompatible types: java.lang.Number cannot be converted to java.lang.Integer
| Integer I = N;
You may be having trouble with something that drove me nuts.
I have been programming for a zillion years, and I swear the way we used the word assign was always:
x = 5 ; // "assign (the value) 5 to (variable) x" or more usually for short, "assign 5 to x"
or rarely, but sometimes
x = 5; // "assign x the value 5"
I have noticed more and more over the years people using English like this (including some major texts in the field by native English speakers)
x = 5; // "assign x to 5"
I never would have said the sentence like that, in a million conversations and emails with like 10000 colleagues...
Here I am showing this with a constant, I find it even MORE confusing when both are variable references.
I swear that for years and years we always said things the first way, all the time, whatever our first languages (human and computer) were.
I had recently given up on this whole issue and just looked carefully as I read each book, watched each video, etc. to see how they phrase the sentence.
For the benefit of everyone who doesn't have the text at all or doesn't have the Kindle Edition, can you quote the exact spot in the Chapter, rather than just the page reference?
Language around assignment statements is obviously a trigger for me, it always feels like at some point we changed the default phrasing in plain English and nobody told me when I see the "Assign x to 5" idiom.