Bug 114777 - [DCR] warn on explicit constructor calls upon primitive types wrapper classes
Summary: [DCR] warn on explicit constructor calls upon primitive types wrapper classes
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-02 11:20 EST by Maxime Daniel CLA
Modified: 2005-11-02 11:20 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maxime Daniel CLA 2005-11-02 11:20:35 EST
Explicit constructor calls upon primitive types wrappers (Boolean, Byte,
Character, Short, Integer, Long, Float and Double) have significant drawbacks
compared to the use of a factory method (such as Boolean.valueOf()) or a boxing
conversion (in 5.0 mode). Especially, the valueOf reference documentation
insists that it is expected to have better space and time behavior than the
constructor, and JLS 5.1.7 requires that some values be treated as singletons by
conforming implementations (true, false, bytes, chars between \u0000 and \u007f
inclusive, ints and shorts between -128 and 127 inclusive). Their use could
raise a specific warning (note that boxing conversions already raise a warning
as of 3.2 M2).

In support for this, the following code:
class X {
  public static void main(String args[]) {
	  Integer i1 = new Integer(0),
	  i2 = (Integer) 0,
	  i3 = Integer.valueOf(0);
	  if (i1 == i2) {
		  System.out.println("i1 == i2");
	  }
	  if (i1 == i3) {
		  System.out.println("i1 == i3");
	  }
	  if (i3 == i2) {
		  System.out.println("i2 == i3");
	  }
  }
}

(only) displays:
i2 == i3