1 Sep 2004 13:48
Re: Problems with Maps
An easy fix to this problem is to force expansion of the GString to a
String.
map.put("${foo}".toString(), value)
map.get("2")
as right now a GString is a different object instance to its static,
constant, immutable String instance.
On 31 Aug 2004, at 17:24, John Wilson wrote:
>
> On 31 Aug 2004, at 17:03, NetBean wrote:
>
>>
>>
>> Hi, I have the following a snippet of
>> a program I am using to store and then
>> postprocess a Map of values... but
>> the behaviour is not as expected
>> when I am retrieving the values using
>> the key.
>>
>>
>> ============= snippet ==============
>>
>> jlick = [:] # init empty map
>> for ( i in 1..5) {
>> k = "val is :${i}";
>> jlick.put("${i}",k);
>> }
>> m = 2;
>>
>> ## I tried to use one of the following
>> ## ways to get the value back using
>> ## a key.
>>
>> #num = jlick.get("${m}");
>> #num = jlick.get("2");
>> #num = jlick.get(2);
>> #num = jlick.2;
>>
>> println("it is >${num}<");
>>
>> ============= snippet ==============
>>
>> Here's my results...
>>
>> # returns correct value
>> m = 2;
>> num = jlick.get("${m}");
>>
>> # returns null for num
>> #num = jlick.get("2");
>>
>
>
> this is a bug.
>
> println "${2}".hashCode() == "2".hashCode()
>
> prints
>
> false
>
> println "${2}" == "2"
>
> prints true
>
> The hashCodes should be identical.
>
> I'll raise an issue and fix it for you.
>
>
>
> John Wilson
> The Wilson Partnership
> http://www.wilson.co.uk
>
>
James
-------
http://radio.weblogs.com/0112098/
RSS Feed