Click here to Skip to main content
13,799,321 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!
<public static <T extends Comparable<T>> int countGreaterThan(T[] anArray, T elem) {
    int count = 0;
    for (T e : anArray)
        if (e.compareTo(elem) > 0)
    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 4:00am
Updated 3-Jan-18 4:06am

1 solution

Rate this: bad
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.

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
Web06 | 2.8.181207.3 | 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