I am a new java learner. Recently I was reading Generic programming and got my self confused with this...
A and A extends B>
First of all, those are completely different constructs used in different contexts.
A is a part of generic type declaration such as
public class A { ... }
It declares generic type A with type parameter T, and introduces a bound on T, so that T must be a subtype of B.
A extends B> is a parameterized type with wildcard, it can be used in variable and method declarations, etc, as a normal type:
A extends B> a = ...;
public void foo(A extends B> a) { ... }
Variable declaration such as A extends B> a means that type of a is A parameterized with some subtype of B.
For example, given this declaration
List extends Number> l;
you can:
Assign a List of some subtype of Number to l:
l = new ArrayList();
Get an object of type Number from that list:
Number n = l.get(0);
However, you can't put anything into list l since you don't know actual type parameter of the list:
Double d = ...;
l.add(d); // Won't compile