Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6208363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:47:43+00:00 2026-05-24T05:47:43+00:00

What is the difference in following 2 lines? public static <T extends Comparable<? super

  • 0

What is the difference in following 2 lines?

public static <T extends Comparable<? super T>> int methodX(List<T> data)
public static <T> int methodX(List<? extends Comparable<? super T>> data)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:47:45+00:00Added an answer on May 24, 2026 at 5:47 am

    Your first option is a “stricter” parametrisation. Meaning, you’re defining the class T with a bunch of restrictions, and then use it later on with List. In your second method, the parameter class T is generic with no conditions, and the Lists class parameter is defined in terms of the parameter T.

    The second way is syntactically different as well, with a ? instead of the first option’s T, because in the parameter definition you aren’t defining the type parameter T but rather using it, so the second method cannot be as specific.

    The practical difference that comes out of this is one of inheritance. Your first method needs to be a type that is comparable to a super class of itself, whereas the second type need only be comparable to an unconditional/unrelated T:

    public class Person implements Comparable<Number> {
        @Override
        public int compareTo(Number o) {
            return 0;
        }
        public static <T extends Comparable<? super T>> int methodX(List<T> data) {
                return 0;
        }
        public static <T> int methodY(List<? extends Comparable<? super T>> data) {
                return 0;
        }
        public static void main(String[] args) {
            methodX(new ArrayList<Person>()); // stricter ==> compilation error
            methodY<Object>(new ArrayList<Person>());
        }
    }
    

    If you change the Comparable of Person to be able to compare Object or Person (the inheritance tree of the base class) then methodX will also work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using LINQ on collections, what is the difference between the following lines of code?
Is there any difference to the following code: class Foo { inline int SomeFunc()
I am trying to read 2 arraylists using the following methods. public static ArrayList<Contestant>
Consider the following code : public class Main implements Vehicle, Car { public static
I came across a difference in speed using the following two structs: public struct
Is there any execution speed difference between the following two lines of code? I
Is there any difference between following two ways of creating an object. Student s1
Question 1 Can anyone tell me if there is any difference between following 2
What is the difference between the following class methods? Is it that one is
What's the difference between the following two pieces of HTML (apologies if there are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.