Question: I have some confusion about generic programming in java:

If Manager is subclass of Employee,

```
Collection<Manager> managers=new Collection<Manager>;  
Collection<Employee> employees=managers;//why illegal?

```

Why the last statement is illegal?

Since according to illustration in the book CORE JAVA,after
the erasion,`Collection<Manager>` and `Collection<Employee>` are
all converted into raw type `Collection`.

Answer: 
If the above were true, then you could take your collection of managers, treat it as a collection of employees, and then put *any* employee into a collection of managers (i.e. not just a manager, but a (say) graduate trainee, a CIO etc.)

It's a little counter-intuitive. An orange **is a** fruit. A list of oranges **is not a** list of fruit (otherwise you could put an apple in it). There's a [concise explanation](http://java.sun.com/docs/books/tutorial/extra/generics/subtype.html) in the Java Generics Tutorial.
> 
> Why the last statement is illegal?
> 
> 
> Since according to illustration in the
>  book CORE JAVA,after the
>  erasion,Collection and
>  Collection are all converted
>  into raw type Collection.
> 
> 
> 

Because generics in java are keeping your code safe during build time. If you want this to work, use wildcard expressions (extends or super).