• Post Reply Bookmark Topic Watch Topic
  • New Topic

JCF Set<?> and Map<?,?>  RSS feed

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have been seeing this syntax used with a number of JCF. Set<?> and Map<?,?>. What does this syntax accomplish and how can i learn more about it?
1. Is it a lambda syntax
2. Those it mean that i can use any return type?
 
Molayo Decker
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So i just learnt that this is a generic way of defining Sets and Maps. I think i am good now
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That has to do with generics, specifically with wildcards.

This is sometimes useful, but it's also a little more advanced and confusing to understand. One very common problem is that people think a Set<?> is a set that can contain any kind of object, but that's not the case; it's a Set that contains objects of one specific type, but what that type is, is unknown. This is sometimes useful if the method that works on the Set for example doesn't care or need to know what exactly the type of the objects in the Set is.
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's a JCF?
 
Ranch Hand
Posts: 461
22
Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think he means-java collection Framework.
 
praveen kumaar
Ranch Hand
Posts: 461
22
Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Molayo,please don't get me wrong but try to not add acronym or any abbreviation in your title or post content,either it is famous or not.it makes really hard for others to understand what you really want to ask or mean,resulting in delay in reply.

Thankyou,
kind regards,
Praveen.
 
Ranch Hand
Posts: 76
3
IntelliJ IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:That has to do with generics, specifically with wildcards.

This is sometimes useful, but it's also a little more advanced and confusing to understand. One very common problem is that people think a Set<?> is a set that can contain any kind of object, but that's not the case; it's a Set that contains objects of one specific type, but what that type is, is unknown. This is sometimes useful if the method that works on the Set for example doesn't care or need to know what exactly the type of the objects in the Set is.


...but more often than not, you see bounded wildcards, like Set<? extends CharSequence> and Set<? super String>.

The former meaning "a Set that contains objects of some unknown type that is a subtype of CharSequence", and the latter meaning "a Set that contains objects of some unknown type that is a supertype of String>. These reference types contain more type information than an unbounded wildcard type, and are more useful in most (not all) cases.
 
Campbell Ritchie
Marshal
Posts: 56610
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that for the purpose of the extends and super keywords, every type is a subtype of itself, and every type is a supertype of itself.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!