diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TAbstractSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/TAbstractSet.java index 1ad4c8a8e..60d225223 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TAbstractSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TAbstractSet.java @@ -15,8 +15,6 @@ */ package org.teavm.classlib.java.util; -import java.util.Arrays; - public abstract class TAbstractSet extends TAbstractCollection implements TSet { public TAbstractSet() { super(); @@ -67,6 +65,13 @@ public abstract class TAbstractSet extends TAbstractCollection implements @Override public int hashCode() { - return Arrays.hashCode(toArray()); + int result = 0; + for (TIterator iter = iterator(); iter.hasNext();) { + E e = iter.next(); + if (e != null) { + result += e.hashCode(); + } + } + return result; } } diff --git a/tests/src/test/java/org/teavm/classlib/java/util/SetTest.java b/tests/src/test/java/org/teavm/classlib/java/util/SetTest.java index 8df585bd4..6cb67d333 100644 --- a/tests/src/test/java/org/teavm/classlib/java/util/SetTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/util/SetTest.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.util.LinkedHashSet; import java.util.Set; import org.junit.Test; import org.junit.runner.RunWith; @@ -121,4 +122,16 @@ public class SetTest { assertNull("Iterator did not return all of expected elements", e); } } + + @Test + public void hashCodeTest() { + Set a = new LinkedHashSet<>(); + a.add("foo"); + a.add("bar"); + Set b = new LinkedHashSet<>(); + b.add("bar"); + b.add("foo"); + + assertEquals(a.hashCode(), b.hashCode()); + } }