• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

<? super T>

 
Ranch Hand
Posts: 182
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
static
<T> int

binarySearch(List<? extends Comparable<? super T>> list, T key)

Here I understood that List argument in binarySearch() should implement Comparable.

1. What is the meaning of <? super T> after Comparable???

2. We can pass only List(ArrayList,Vector,LinkedList) to Collections.binarySearch and Collections.sort methods. we cannot pass Set and

Map. Correct??? Means we can only sort and search List only???
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1. What is the meaning of <? super T> after Comparable???



Comparable itself, is also a generic. And the method is a generic method, that takes a type T. The first parameter is a List of sone type that extends Comparable, which is used to compare some type that is a super of the type specified by the generic method.

Henry
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...Comparable<? super T>... I believe signifies that whatever type it is that is passed in as a key to binarySearch()will implement Comparable generically, typing the interface for T or anything that T extends (superclasses).
Perhaps it is understood that Comparable is generic for type Object by default.

And that's right about Lists being the only type of Collection that works for sort. You would use the tree
implementations of Set and Map to get sorted content from those collections.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic