This week's book giveaway is in the Go forum.
We're giving away four copies of Head First Go and have Jay McGavren on-line!
See this thread for details.
Win a copy of Head First Go this week in the Go 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Jeanne Boyarsky and Scott Selikoff OCP book  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have a little question about generics.

On p119 i modify the code below


by this code


And the answer is :
java
java
1
1

Now here is my question: what is the need of the Unbounded Wildcards?
I mean, in which case we must use the Unbounded Wildcard instead of a generic method?
And in which case we must use a generic method instead of an unboundwildcard.

In my point of view, regarding the above example, they do the same thing.
but generic method seems to be more readable.

Thank you for your answer.

regards
Vincent



 
Greenhorn
Posts: 17
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unbounded wildcard is immutable. So you can not add any element to List<?> list of printList(List<?> list). You can not add because you don't know what is going to come in place of wildcard(?).

But for the second method printList2(List<T> list), the list is not immutable. You can add new elements to the list of Type T. Like T t = null; list.add(t).

 
vincent Lepore
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello SwapanB,
Thank you very much for your answer.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!