aspose file tools*
The moose likes Beginning Java and the fly likes Adding String to an Integer ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Adding String to an Integer ArrayList " Watch "Adding String to an Integer ArrayList " New topic
Author

Adding String to an Integer ArrayList

Vivek Kr Singh
Ranch Hand

Joined: Oct 12, 2007
Posts: 56


Why there is no error on line 20 at runtime?


SCJP 1.4
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

With generics, no type checking is done at runtime; they're just a compile-time thing. By passing your List<Integer> to a method accepting just List as an argument, you've completely defeated the type system.


[Jess in Action][AskingGoodQuestions]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19794
    
  20

But the compiler should have given you a warning that you are using a so-called raw type. Whenever you ignore or suppress these warnings, the compiler simply puts all responsibilities on the programmer.

Your example is just waiting for a ClassCastException to happen once you really start using the List, and it all stems from ignoring the warning.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding String to an Integer ArrayList