I\'m not sure why the last statement in the following code is illegal. Integer should be a subtype of ?, so why can\'t I assign it to b
Here is a short summary of what you can and cannot do with generics:
List extends Number> listOfAnyNumbers = null;
List listOfNumbers = null;
List listOfIntegers = null;
listOfIntegers = listOfNumbers; // Error - because listOfNumbers may contain non-integers
listOfNumbers = listOfIntegers; // Error - because to a listOfNumbers you can add any Number, while to listOfIntegers you cannot.
listOfIntegers = listOfAnyNumbers; // Error - because listOfAnyNumbers may contain non-integers
listOfAnyNumbers = listOfIntegers; // OK - because listOfIntegers is a list of ?, where ? extends Number.
listOfNumbers = listOfAnyNumbers; // Error - because listOfAnyNumbers may actually be List, to which you cannot add any Number.
listOfAnyNumbers = listOfNumbers; // OK - because listOfNumbers is a list of ?, where ? extends Number.