diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ObjectNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ObjectNativeGenerator.java index 48258dc2f..7f09e716e 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ObjectNativeGenerator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ObjectNativeGenerator.java @@ -61,7 +61,9 @@ public class ObjectNativeGenerator implements Generator, DependencyPlugin { ValueType.object(classClass))); writer.append("cls = ").appendClass(classClass).append('.').appendMethod(createMethodRef) .append("();").newLine(); - writer.append("cls.$data = ").append(thisArg).append(".$class;").newLine().outdent().append("}").newLine(); + writer.append("cls.$data = ").append(thisArg).append(".$class;").newLine(); + writer.append(thisArg).append(".$class.classObject = cls;").newLine(); + writer.outdent().append("}").newLine(); writer.append("return cls;").newLine(); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TObjectTests.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TObjectTests.java index 08baad0be..12d0bd07f 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TObjectTests.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TObjectTests.java @@ -27,4 +27,22 @@ class TObjectTests { Object b = a; assertEquals(a, b); } + + @Test + public void multipleGetClassCallsReturnSameValue() { + Object a = new Object(); + assertSame(a.getClass(), a.getClass()); + } + + @Test + public void sameClassesAreEqual() { + Object a = new Object(); + Object b = new Object(); + assertSame(a.getClass(), b.getClass()); + } + + @Test + public void properInstanceDetected() { + assertTrue(Object.class.isInstance(new Object())); + } }