Generic methods to find the maximal element in part of a list This is the question from Oracle docs:


  Write a generic method to find the maximal element in the range
  [begin, end) of a list.


I had my implementation like this:

    public static &lt;T extends Comparable&gt; T maximalElement (List&lt;T&gt; list, int from, int to) {
        T max = list.get(from);
        for (int i = from + 1; i &lt; to; i++) {
            T elem1 = list.get(i);
            if (elem1.compareTo(max) &gt; 0) {
                max = elem1;
            }
        }
        return max;
    }


When I viewed the answer, it was something like this:


     public static &lt;T extends Object &amp; Comparable&lt;? super T&gt;&gt; T max (List&lt;? extends T&gt; list,
                                                                    int begin, int end) {

        T maxElem = list.get(begin);

        for (++begin; begin &lt; end; ++begin) {
            if (maxElem.compareTo(list.get(begin)) &lt; 0) maxElem = list.get(begin);
        }
        return maxElem;
    }



So, I got the results running like this:

        List&lt;Integer&gt; c = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        System.out.println(Test.maximalElement(c, 3, 8));
        System.out.println(Test.max(c, 3, 8));


Results are same, so I am quite excited that my version of generics is more simpler than one implemented in the answer. So, I want to check if my implemented version is really simpler and okay or am I not seeing something? Because oracle developers are not dumb enough to complex things out for nothing.

So, can you experts please help me understanding the difference or scenarios where my implemented version fails?
I'd just say to go with your implementation; just because it is easier to read! Also, you only .get() from the list once, whereas the proposed solution does it twice.

Shorter is not a synonym for better!

However, the generics are not good; you should at least use &lt;T extends Comparable&lt;? super T&gt;&gt;. Not sure why the proposed solution uses Object as a lower bound...