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

Summary: Hint for identity comparison of numeric types, including unboxing cases
Product: java Reporter: fommil <fommil>
Component: HintsAssignee: Svata Dedic <sdedic>
Status: NEW ---    
Severity: blocker    
Priority: P3    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

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.

@see http://java.sun.com/docs/books/jls/third_edition/html/conversions.html

================
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);
	}
}