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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:08:53+00:00 2026-05-15T18:08:53+00:00

In Java, all numeric types extend from java.lang.Number. Would it be a good idea

  • 0

In Java, all numeric types extend from java.lang.Number. Would it be a good idea to have a method like the following:

public boolean areEqual(Number first, Number second) {
    if (first != null && second != null) {
        return first.equals(second);
    }
}

I’m concerned about cases where a double 2.00000 does not equal an int 2. Are these handled by the built-in equals? If not, is there any way to write a simple number compare function in java? (external libraries such as apache commons are ok)

  • 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-15T18:08:54+00:00Added an answer on May 15, 2026 at 6:08 pm

    A Double is NEVER equals to an Integer. Moreover, a double is not the same as a Double.

    Java has primitive types and reference types. The truly numeric types in Java do not extend from Number, because they’re primitives.

    You may want to consider a system where you’re not mixing types, because that usually will cause a lot of trouble with implicit/explicit conversions that may/may not lose information, etc.

    Related questions

    On int vs Integer:

    • What is the difference between an int and an Integer in Java/C#?
    • Is Java fully object-oriented?

    On Number comparison:

    • Why doesn’t java.lang.Number implement Comparable?
    • Comparing the values of two generic Numbers

    See also

    • Java Language Guide/Autoboxing
    • JLS 4.2 4.2 Primitive Types and Values

      The numeric types are the integral types and the floating-point types.
      The integral types are byte, short, int, and long and char.
      The floating-point types are float and double.


    On mixed-type computation

    Mixed-type computation is the subject of at least 4 puzzles in Java Puzzlers.

    Here are various excerpts:

    it is generally best to avoid mixed-type computations […] because they are inherently confusing […] Nowhere is this more apparent than in conditional expressions. Mixed-type comparisons are always confusing because the system is forced to promote one operand to match the type of the other. The conversion is invisible and may not yield the results that you expect

    Prescription: Avoid computations that mix integral and floating-point types. Prefer integral arithmetic to floating-point.

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

Sidebar

Ask A Question

Stats

  • Questions 532k
  • Answers 532k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Big-O means <= and big Omega means >=, so a… May 17, 2026 at 12:15 am
  • Editorial Team
    Editorial Team added an answer The Tomcat docs for JNDI Datasources contain complete examples how… May 17, 2026 at 12:15 am
  • Editorial Team
    Editorial Team added an answer Use a SoundPool combined with an OnTouchListener. In your onTouch(..)… May 17, 2026 at 12:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

All, I've been a Java developer for 10 years...when it comes to managing numerical
I'm using the Java matcher to try and match the following: @tag TYPE_WITH_POSSIBLE_SUBTYPE -PARNAME1=PARVALUE1
I have excel file with such contents: A1: SomeString A2: 2 All fields are
This is driving me bonkers. I'm writing a web app in Java and all
I've created a webservice and used Axis2 to generate all skeleton java classes. Then
hey all i am trying to make a data output stream in php to
This answer hit a nerve with me on something I have never understood with
I have tried to find information about this but have come up empty handed:
I'm using a Java StreamTokenizer to extract the various words and numbers of a
What is the best way to approach translating this code into Java? (the section

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.