It is wrong to use the wildcard when declaring collections:
Does that mean that the wildcard can only be used when specifying parameters and return types(for collections)
But that it can be used when declaring other types(that are not collections)??
There is no special treatment for collections. The places where you can't use a wildcard are:
1. In the generic type declaration for a generic method or class.
2. In an instantiation expression, something like List<T> = new ArrayList<? extends T>
Those are the two that I am aware of. If I missed something, I am sure someone will correct me.
All code in my posts, unless a source is explicitly mentioned, is my own.
We use generic programming to bound the types allowed.
If we say <T extends Number>, we are saying, T is number or T is subtypes of Number. So here T has a upper boundary that is Number, that we know.
But if we say <T super Number>, we would say, T is number or T is supertypes of Number. So this will become like saying T could be any object, As Object is the supertype of Number, that does not limit the type of T. This way T could be any object, as every type in java except primitives is an object. We cannot say T has a upper boundary.