File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Could we create an object in type List?

 
Div Raj
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If we are giving--
List<Smtable> svalues = new List<Smtable>();
it will show some Error.
But...
if we are creating an object in ArrayList like this--
ArrayList<Smtable> svalues = new ArrayList<Smtable>();
no Error is shown.

Why is it so? can't we create an object in type List?

And when it is given like this---
List<Smtable> smlabels = jobmgr.getSmvalues();
it wont show any Error and works fine.

Could anyone help me?


Thanks
-------
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.util.List is an interface. You cannot "new" or instantiate an interface. However, java.util.ArrayList is one implementation of a List interface, meaning...

public class ArrayList implements List { ... }

And when it is given like this---
List<Smtable> smlabels = jobmgr.getSmvalues();
it wont show any Error and works fine.


Because jobmgr.getSmvalues() probably returns some implementation of List, like an ArrayList.
 
Div Raj
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Gregg
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic