I would say that is a bug in GWT. The HashMap.get() contract specifies
in which order it will call equals() on the keys in order to check
equality. So it shouldn't matter that there's an asymmetry in your code
(ie that String.equals(OtherStringClass) will always return false
because they're different classes, whereas
OtherStringClass.equals(String) may return true)
Paul
Francisco wrote:
> I am experiencing different behavior from host mode and web mode
> regarding HashMap. I built a simple code which reproduces this error.
> You can see that HashBug.getHTML() output is not the same in host and
> web modes.
> I've tested with gwt-windows-1.5.3, FireFox and IE.
>
> Is it a bug?
>
> Regards, Francisco.
>
>
>
> package project.client;
>
> import java.util.HashMap;
>
> import com.google.gwt.user.client.ui.HTML;
>
> public class HashBug {
> private HTML html;
>
> private class OtherStringClass{
> String value;
> public OtherStringClass(String value){
> this.value = value;
> }
> public String getValue(){
> return this.value;
> }
> @Override
> public boolean equals(Object obj) {
> return value.equals(obj);
> }
> @Override
> public int hashCode() {
> return this.value.hashCode();
> }
> }
> public HashBug(){
> HashMap<String, Integer> map = new HashMap<String, Integer>();
> String testString = "test";
> OtherStringClass otherTestString = new
> OtherStringClass(testString);
> map.put(testString, new Integer(1));
>
> String text = "";
>
> Integer fromString = map.get(testString);
> if(fromString != null) text += "From string = " +
> fromString.intValue
> () + " ";
> Integer fromOhter = map.get(otherTestString);
> if(fromOhter != null) text += "From other = " +
> fromOhter.intValue
> ();
>
> html = new HTML(text);
> }
>
> public HTML getHTML(){
> return this.html;
> }
> }
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---