Now blogging at diego's weblog. See you over there!

add(E), but remove(Object)?

Martin notes that in Java 5, the new-super-shiny-generics-enabled Collection interface has some inconsistencies. Most notably, the add method is dependent on the specific type for the collection, while remove and contains (most notably) are not. Here are the method contracts:

boolean add(E o)
boolean remove(Object o)
boolean contains(Object o)
Martin wonders why the discrepancy. I see two options.

Option one is a hilarious story that involves a monkey, a pantsuit, and a cherry cake interfering with the programmer's work and making her/him commit the grievous error for which she/he will feel regret the rest of her/his days. Let's call this the low-probability option.

Option two is that the Architecture Astronauts involved in the spec were carried away by the following definition of the remove method :

Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if this collection contains one or more such elements. Returns true if this collection contained the specified element (or equivalently, if this collection changed as a result of the call).
and this one from the contains method:
Returns true if this collection contains the specified element. More formally, returns true if and only if this collection contains at least one element e such that (o==null ? e==null : o.equals(e)).
My theory (and hoyven mayven, this is a theory only!) is that because the formal definition involves the use of the equals method and the method specifies an Object (and cannot, given that is the class at the top of the Java object hierarchy, know anything about "E") then the contract for contains and remove also follows with Object rather than E.

Sounds reasonable?

If anyone has the skinny on this, please pass it on. Alternative theories will also be appreciated. Especially if they involve monkeys (monkey-butlers are also accepted).

Categories: soft.dev
Posted by diego on February 7, 2005 at 10:23 PM

so THAT'S why!

I had a sequence of reactions to this article in the New York Times which deals with Google's recent approval as an Internet registrar.

First, the obligatory rolling of eyes at people "wondering" and "worrying" and "speculating" about every single move of Google. Let the guys do their work in peace ok? If it's world domination, then fine, let them try.

Second, was a raised eyebrow as I read the following:

Eileen Rodriguez, a Google spokeswoman, hardly quelled the speculation by explaining that the whole thing was really a learning opportunity for the company.
To this, I followed with an interested (muttered) "A-ha". But then the actual quote went on:
Google "has become a domain name registrar to learn more about the Internet's domain name system," she said recently in an e-mail message. "While we have no plans to register domains at this time, we believe this information can help us increase the quality of our search results."
To this, I just laughed out loud, quite literally, for several seconds. I still giggle at it every time I read it.

Come on boys! That's the line you feed to your spokespeople? "We became a domain name registrar to learn more about the Internet's domain name system"?!?!?? Yes!

LOL LOL ROFL!

Maybe this is practice, you know.

When Google announces they are releasing, say, a web browser, they will say "We are not interested in the browser business, this is just to learn more about web browsers and stuff."

Then, if they want to release an Operating System: "We are not interested in OSes. This is just to learn more about computers. And stuff."

And Larry or Sergey will show up and whisper something in the ear of whoever is giving the interview, and then they will add: "Right. To improve search results too. You know?"

Cue Mr. Burns: "And remember... a shiny new donkey for whoever brings me the head of Colonel Montoya."

And still laughing... :)

PS: Before anyone starts "explaining". Yes, I know that some of the info available only to registrars, and that can help, etc, etc. I just find the spokeperson's choice of words quite hilarious (aside from imagining the innocent look on their eye while they essentially say, straight-faced "Thinking of a product that is not pure search engine? Us? Noooooooooooo!").

Don't you? :)

Categories: technology
Posted by diego on February 7, 2005 at 1:26 PM

Copyright © Diego Doval 2002-2011.