Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Can you break generics?

796386Jun 4 2010 — edited Jun 7 2010
Hi,
Generics as we all know enforce type saftey. But, it is easy to corrupt generics when you mix generics and non-generic types. For example:
		
List<Car> list = new ArrayList<Car>();
List list2 = new ArrayList();
list2.add("tony");
list = list2;
Car car = list.get(0);    // this will throw an exception.
Is there any way you can corrupt generics by mixing one generic type with another generic type, or is that absolutely and always impossible.
Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 5 2010
Added on Jun 4 2010
11 comments
158 views