This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

List interface vs. List class  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

What is the difference between the interface List<E> and class List ? They seem to be performing similar operations. Also what does the "E" stand for in List<E>? I've also seen code where there is a question mark in it List<?> .

Thank you guys!

 
Sheriff
Posts: 11747
191
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.util.List is an interface in the Standard Java API. In List<E>, E is a type parameter and by convention, it stands for Element. Other type parameter conventions are listed here: http://docs.oracle.com/javase/tutorial/java/generics/types.html

The ? stands for an unknown type. Read more about it here: http://docs.oracle.com/javase/tutorial/extra/generics/wildcards.html
 
Junilu Lacar
Sheriff
Posts: 11747
191
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot to mention that as far as I know there is no List class in the Standard Java API. java.util.List is an interface that is part of the Java Collections API.
 
Sheriff
Posts: 23451
46
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:I forgot to mention that as far as I know there is no List class in the Standard Java API.



Unfortunately there is the class java.awt.List. Obsolete to be sure, but it's still there and not even deprecated.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:as far as I know there is no List class in the Standard Java API


You mean you've never used AWT to produce a GUI ?
 
Author and ninkuma
Marshal
Posts: 66541
160
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joanne Neal wrote:

Junilu Lacar wrote:as far as I know there is no List class in the Standard Java API


You mean you've never used AWT to produce a GUI ?


You find this surprising? I've been working with Java since 1998 and never used AWT.
 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu is a young whipper-snapper who missed the early days of Java

It is possible to refer to both within the same class with some extra effort. Either always use fully qualified class names (java.awt.List and java.util.List) or you can import one of them and then just use "List" for that one. For clarity it's probably better to do the former. (This goes for all cases where you have to work with more than one class/interface of the same name - luckily, these cases are rare.)
 
Ulf Dittmer
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:I've been working with Java since 1998 and never used AWT.


That only proves that in terms of length of Java experience you're a junior guy compared to some of the people here :-)
 
Junilu Lacar
Sheriff
Posts: 11747
191
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Junilu is a young whipper-snapper who missed the early days of Java


Ha ha, this "young whipper-snapper" just went through the rite of passage into the later stage of life this morning with his first-ever colonoscopy. But I'm guilty as charged, never used AWT and I don't think I ever will. There is a limit to the kind of indignities I'm willing to endure and AWT is definitely over that limit
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:You find this surprising? I've been working with Java since 1998 and never used AWT.


I guess my comment needed an emoticon to indicate mock surprise.
By the time I'd checked the javadocs to find out what the OP was talking about, Junilu had already replied, so not wanting to have totally wasted my time, threw in that off-the-cuff comment, by which time Paul had also replied. And then to top it all off, my attempt at humour was completely wasted on you. I'd have been better off ignoring this thread altogether.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66541
160
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No probs!
 
Ian Lafuente
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for the clarification and humor!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!