This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 164089 - Hint for identity comparison of numeric types, including unboxing cases
Summary: Hint for identity comparison of numeric types, including unboxing cases
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Svata Dedic
Depends on:
Reported: 2009-04-29 16:23 UTC by fommil
Modified: 2013-09-02 14:20 UTC (History)
0 users

See Also:
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description fommil 2009-04-29 16:23:36 UTC
Most people forget that when performing an identity comparison between numeric/boolean types, they might be using boxed versions... not the primitives. 
The example shows a typical case. There should be a hint to either:-

- unbox the Type to a primitive, e.g. use .longValue()
- use .equals()

The hint could serve as a reminder for case b below when dealing with (at least)

- Boolean
- Byte
- Character
- Short
- Integer
- Long
- Float
- Double

similar to the way there is a warning when String is identity compared.


public class Scratch {

	public static final void main(String[] args) {
		Long n = new Long(0);
		// XXX not always true! 0 is being boxed to Long
		System.out.println(n == 0);

		Long m = new Long(0);
		System.out.println(n == m);