Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A <code>Double</code> is <strong><em>NEVER</em></strong> <code>equals</code> to an <code>Integer</code>. Moreover, a <code>double</code> is not the same as a <code>Double</code>.</p> <p>Java has primitive types and reference types. The truly numeric types in Java do not extend from <code>Number</code>, because they're primitives.</p> <p>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.</p> <h3>Related questions</h3> <p>On <code>int</code> vs <code>Integer</code>:</p> <ul> <li><a href="https://stackoverflow.com/questions/564/what-is-the-difference-between-an-int-and-an-integer-in-java-c"> What is the difference between an int and an Integer in Java/C#? </a></li> <li><a href="https://stackoverflow.com/questions/2054662/is-java-fully-object-oriented">Is Java fully object-oriented?</a></li> </ul> <p>On <code>Number</code> comparison:</p> <ul> <li><a href="https://stackoverflow.com/questions/480632/why-doesnt-java-lang-number-implement-comparable">Why doesn't <code>java.lang.Number</code> implement <code>Comparable</code>?</a></li> <li><a href="https://stackoverflow.com/questions/2683202/comparing-the-values-of-two-generic-numbers">Comparing the values of two generic Numbers</a></li> </ul> <h3>See also</h3> <ul> <li><a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/autoboxing.html" rel="nofollow noreferrer">Java Language Guide/Autoboxing</a></li> <li><a href="http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2" rel="nofollow noreferrer">JLS 4.2 4.2 Primitive Types and Values</a> <blockquote> <p>The <em>numeric types</em> are the integral types and the floating-point types. The integral types are <code>byte</code>, <code>short</code>, <code>int</code>, and <code>long</code> and <code>char</code>. The floating-point types are <code>float</code> and <code>double</code>.</p> </blockquote></li> </ul> <hr> <h3>On mixed-type computation</h3> <p>Mixed-type computation is the subject of at least 4 puzzles in <a href="http://javapuzzlers.com/" rel="nofollow noreferrer"><em>Java Puzzlers</em></a>.</p> <p>Here are various excerpts:</p> <blockquote> <p>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</p> <p><strong>Prescription</strong>: Avoid computations that mix integral and floating-point types. Prefer integral arithmetic to floating-point.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload