Click here to Skip to main content
13,589,795 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
I found this code in JAVA DOCS
public interface Comparable<T> {
    public int compareTo(T o);
}

Which is Comparable Interface!
And
<public static <T extends Comparable<T>> int countGreaterThan(T[] anArray, T elem) {
    int count = 0;
    for (T e : anArray)
        if (e.compareTo(elem) > 0)
            ++count;
    return count;
}


What I have tried:

There is line of code like this
e.compareTo(elem) > 0

e is implements Comparable
but how e can use compareTo method without implements it?
Posted 3-Jan-18 3:00am
Updated 3-Jan-18 3:06am
v4

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

That basically says countGreaterThan method works for T provided T (actually its superclass) implements the Comparable interface.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.180618.1 | Last Updated 3 Jan 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100