Languages

Java - What is difference between List<?> and List<Object>?

6 points
Asked by:
Wallace
636

As in the question.

I am thinking what is difference between List<?> and List<Object>?

Each class extends Object, so why it was introduced?

1 answer
6 points
Answered by:
Root-ssh
178180

By using List<?> you are able to assign to variable types of:

  • List<String>,
  • List<Integer>,
  • List<Boolean>,
  • List<Object>,
  • etc.

By using List<Object> you are not.

Example source code:

 

0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join