wood burning stoves 2.0*
The moose likes Java in General and the fly likes Object Creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Object Creation" Watch "Object Creation" New topic
Author

Object Creation

susha pillu
Greenhorn

Joined: Jul 25, 2001
Posts: 8
Why
Collection l = new ArrayList();
is allowed but not
List l = new ArrayList();
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

If the error you get is:
l is already defined in [ wherever you've defined it ]

Then your problem is you've used the same variable name twice. Otherwise, I can compile this:
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Object Creation
 
Similar Threads
Why in collection Objects are assigned to super reference
passing List to method that wants ArrayList
ArrayList
List implementation
What is the difference