Re: [Syntax-jsr] Re: [Java Spec Report] Re: JSR 201 autobox comments

Neal M Gafter <[email protected]> Mon, 12 Apr 2004 11:30:43 -0700
Newsgroups gmane.comp.java.spec-report
Organization Sun Microsystems
Message-ID <[email protected]>
visitor_pattern wrote:
> The .equals problem has a clean solution: introduce an operation
> .primEquals on the boxed primitives that matches the behavior of == on
> primitives.  There is no operation on primitives corresponding to
> .equals but it could easily be added.  For boxed primitives, the
> semantics of .equals would be defined as it is for the existing
> wrapper classes so that autoboxing could be used with hash tables
> without any surprises.

I think you're forgetting about the surprise that the new boxed types could not 
be used in collections at all.  If the equals() method complies with the 
existing ones on the existing wrapper classes, then you would not be able to 
write a contract for .equals() on the interface types that both satisfies the 
implementation in the existing wrapper classes and allows meainingful use in 
Collections.

For example, suppose the new int wrapper interface is called IInteger.  If you 
wanted to make a map from int to Something you'd write

	Map<IInteger,Someting> m;

Since the autoboxing wouldn't box to the existing wrappers - it can't because of 
a problem with transitivity - but rather it boxes to the new interfaces, you'd 
want to use the new interface here to take advantage of boxing.  Now suppose a 
client has
	m.put(1, something1);
and then
	char c = 1;
nwo the call
	m.get(c);
returns null, because the java.lang.Character with value 1 must be !equals() to 
the java.lang.Integer with value 1.

In other words, it just doesn't work.


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com.  Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/5cFolB/TM
---------------------------------------------------------------------~->

To unsubscribe from this mailing list, send an email to:
[email protected]
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/java-spec-report/

<*> To unsubscribe from this group, send an email to:
     [email protected]

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/