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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:35:16+00:00 2026-05-23T13:35:16+00:00

I would like to perform an operation on two generics argument of the same

  • 0

I would like to perform an operation on two generics argument of the same type both extending Number.

Is it Possible?
I always used to call methods on generic arguments, but seems there is some problem using operators (The operator + is undefined for the argument type(s) T, T).

public static <T extends Number> T sum(T a, T b){
    return a+ b;
}

What am I doing wrong?

EDIT:
I try to improve a little bit my question. I understood that operators are not defined for type Number. It’s a bit sad this thing because it would be nice to perform such an operation without introducing new interfaces like suggested by @Victor Sorokin.

But I still don’t understand one thing: if operators are not implemented in the class Number, then at least in Double class should be implemented because I can use + operator with double.
Neither these line of code will compile:

public static <T extends Double> T sum(T a, T b){

    T c = a +b;
}

why?

  • 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-23T13:35:17+00:00Added an answer on May 23, 2026 at 1:35 pm

    It’s not possible because Number doesn’t have a + operator associated with it. In particular, you can’t do this:

    Number a = new Integer(1);
    Number b = new Integer(2);
    Number c = a + b;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to synchronize two thread (working on the same C++ map) using
In vim/gvim I would like to be able to move to the front and
Say I have an object for U.S. state, and I want to perform a
Could someone point out the idea of overloading operator== to perform deep object comparison
I have a table of forum posts, and want to improve the basic search
I'm writing an image manipulation app (e.g. operations include blurring, rotating, scaling, merging, flood
This is pseudo homework (it's extra credit). I've got a BST which is an
I am working on an app that involves evaluating modifications made to vehicles, and
Imagine to have a Desktop application - could be best described as record keeping
Say I have a common pattern with a Customer object and a SalesOrder object.

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.