This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Generics

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does List and List<Object> are same or different in java?
 
Marshal
Posts: 66266
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
List<?> is different too. It is pronounced, “List of unknowns,” or similar. It means you are going to have a specific type for the Es in that List, but you haven't yet said what type. You can pass a List<XYZ> to a List<?> reference, but you usually can't add elements to the List.
Plain simple List mean you aren't saying anything about its Es; it could contain anything, but you will have to cast its elements if you want to use it. This is what we used to have to write when I learnt Java1.4.2:-You should be able to see how error‑prone that technique is; it caused lots of complaints because other languages impemented generics and Java® didn't have them.
A List<Object> should mean that you are adding anything to it, but using all its elements as plain simple Objects. At least in theory it does. If you want to use any of its elements as a narrower type, you will have to cast it: again an error‑prone action.

[additional]Plain simple List is often called a raw type.
 
Well don't expect me to do the dishes! This ad has been cleaned for your convenience:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!