From: Robert Klemme on
On 12 Mai, 06:11, Lew <no...(a)lewscanon.com> wrote:
> Roedy Green writes:
> >> Can anyone think of a way to write a method that takes an
> >> array of X, and produces a HashMap<Key,X>
> Stefan Ram wrote:
> > HashMap<  Key, X>m( final X[] x ){ return new HashMap<  Key, X>(); }
>
> That is genius.  This is my favorite answer so far.
>
> Most of the other answers just made my head hurt.  I wonder what the point is.
>   Rephrasing, what is the value?

I am sorry your brain hurts. ;-)

Actually it did not occur to me that the code above is a valid
implementation of the requirements before. Rereading Roedy's original
posting I think it *is* a valid implementation although I must say
that I found his question a bit vague. So, Roedy, what is it that you
want?

[ ] an empty HashMap with correct types
[ ] a filled HashMap where keys are found based on the values in the
array
[ ] something else, namely
_________________________________
_________________________________

Kind regards

robert
From: Arne Vajhøj on
On 12-05-2010 00:11, Lew wrote:
> Roedy Green writes:
>>> Can anyone think of a way to write a method that takes an
>>> array of X, and produces a HashMap<Key,X>
>
> Stefan Ram wrote:
>> HashMap< Key, X>m( final X[] x ){ return new HashMap< Key, X>(); }
>
> That is genius. This is my favorite answer so far.

I assume that it was a sarcastic comment on the level of precise
description in Roedy's question.

> Most of the other answers just made my head hurt. I wonder what the
> point is. Rephrasing, what is the value?

The point in Roedy's questions seems very clear to me. He want
to reuse some code for a conversion that he apparently does
frequently.

Arne


From: Roedy Green on
On Tue, 11 May 2010 02:22:07 -0700 (PDT), Robert Klemme
<shortcutter(a)googlemail.com> wrote, quoted or indirectly quoted
someone who said :

>Roedy did not state how exactly the key is obtained for a particular
>value although he seems to insinuate that it's a property of the
>value.

I presumed the key was either a string field in the value or a get
method on the value object for a string. For a somewhat more
difficult problem, allow the key type to be an arbitrary Object of
some generic type.
--
Roedy Green Canadian Mind Products
http://mindprod.com

Beauty is our business.
~ Edsger Wybe Dijkstra (born: 1930-05-11 died: 2002-08-06 at age: 72)

Referring to computer science.
From: Roedy Green on
On 12 May 2010 03:14:50 GMT, ram(a)zedat.fu-berlin.de (Stefan Ram)
wrote, quoted or indirectly quoted someone who said :

>>Can anyone think of a way to write a method that takes an
>>array of X, and produces a HashMap<Key,X>
>
>HashMap< Key, X >m( final X[] x ){ return new HashMap< Key, X >(); }

A lawyer's answer that answers the letter of the spec but not the
spirit.
--
Roedy Green Canadian Mind Products
http://mindprod.com

Beauty is our business.
~ Edsger Wybe Dijkstra (born: 1930-05-11 died: 2002-08-06 at age: 72)

Referring to computer science.
From: lewis on
Roedy Green wrote:
>>>Can anyone think of a way to write a method that takes an
>>>array of X, and produces a HashMap<Key,X>
>

Stefan Ram wrote, quoted or indirectly quoted someone who said :
>>HashMap< Key, X >m( final X[] x ){ return new HashMap< Key, X >(); }
>

Roedy Green wrote:
> A lawyer's answer that answers the letter of the spec but not the
> spirit.
>

That's exactly what makes is so brilliant and funny.

You could, should you have a sense of humor, also call it a comedian's
answer that answers the letter of the spec but not the spirit.

But yeah, there is that nasty precondition.

Shakespeare wrote, "First, we kill all the lawyers" as a recipe for
how to destabilize a society.

--
Lew