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 8440867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:25:01+00:00 2026-06-10T08:25:01+00:00

I have a rather simple question. I can’t find an answer by searching though.

  • 0

I have a rather simple question. I can’t find an answer by searching though.

Is there a difference in these two code-fragments? And what is the difference?

Fragment1:

public class BinaryTree<T extends Comparable<? super T>> {
   ...
   public <E extends T> void add(E value) {
      ...
   }

   public <E extends T> void add(E value, Node node) {
      ...
   }
   ...
}

Fragment2:

public class BinaryTree<T extends Comparable<? super T>> {
   ...
   public void add(T value) {
      ...
   }

   public void add(T value, Node node) {
      ...
   }
   ...
}

Fragment1 specifies explicitly, that the parameter value must be either of type T or a subtype of type T.

Fragment2 specifies, that the parameter value must be of type T. But from my little knowledge and experience I think that I can also supply a subtype of T here. So same as fragment1.

I looked at the disassembled byte codes of these two fragments. Indeed there is a difference:

<   public <E extends T> void add(E);
---
>   public void add(T);

That just reflects the source code …

I just don’t get the meaning. And I also can’t find an example application, which shows the difference.

Thanks for comments.

  • 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-06-10T08:25:02+00:00Added an answer on June 10, 2026 at 8:25 am

    In this case there is no difference. Let’s take for example a BinaryTree<Number> and try adding an Integer:

    BinaryTree<Number> numTree = new BinaryTree<>();
    Integer i = 1;
    numTree.add(i);
    

    With fragment 1, E may evaluate to Integer, but that’s superfluous in this case. Integer is a Number, and you could just as well specify Number for E:

    numTree.<Number>add(i);
    

    For this reason the second snippet is no different than the first, and less confusing for not declaring an unnecessary type parameter.


    There are situations where an additional type parameter would be useful. Imagine for some reason you wanted to return the passed in value:

    public <E extends T> E add(E value) {
       ...
       return value;
    }
    
    public <E extends T> E add(E value, Node node) {
       ...
       return value;
    }
    

    This would now be useful to the caller:

    Integer i2 = numTree.add(i);
    

    With the second snippet that wouldn’t be possible, and numTree.add could only return a Number even if you passed in an Integer.

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

Sidebar

Related Questions

Simple question, but I can't seem to find the answer. I have a 200px
Have a rather simple question. Does anyone knows if i can use jparallax both
Apologies for the rather simple question, I just can't seem to find ANY good
I have a rather interesting question that seems simple to answer, yet I have
I have a very simple (rather stupid) question, I hope someone can clear my
I have very simple question that I cannot find the answer to. In the
I think, the answer to my question is rather simple, but I just can't
Simple question but I can't find the answer anywhere. No search strategy so far
I have a rather simple question that I could normally debug myself, but I
my question is rather simple, if you have an pure virtual class (interface) but

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.