File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Generics" Watch "Generics" New topic


Juan Manuel Alberto de los Santos
Ranch Hand

Joined: Jun 26, 2008
Posts: 48

Why this compiles ??

if i am passing an object(animal) to the method go (who can only accept integers)

Thanks in advance !
[ July 09, 2008: Message edited by: Juan Manuel Alberto de los Santos ]
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

It compiles so generics are compatable with legacy code. However, you will have seen a warning:

Type safety: The expression of type List needs unchecked conversion to conform to List<Integer>

letting you know what you are doing is not necessarily safe.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
I agree. Here's the link:
subject: Generics
It's not a secret anymore!