diff --git a/platform/src/main/java/org/teavm/platform/Platform.java b/platform/src/main/java/org/teavm/platform/Platform.java index 6f6b02d1e..5ce1184b5 100644 --- a/platform/src/main/java/org/teavm/platform/Platform.java +++ b/platform/src/main/java/org/teavm/platform/Platform.java @@ -33,6 +33,8 @@ public final class Platform { private Platform() { } + private static boolean newInstancePrepared; + @InjectedBy(PlatformGenerator.class) public static native PlatformObject getPlatformObject(Object obj); @@ -85,7 +87,10 @@ public final class Platform { public static native int nextObjectId(); public static T newInstance(PlatformClass cls) { - prepareNewInstance(); + if (!newInstancePrepared) { + prepareNewInstance(); + newInstancePrepared = true; + } return newInstanceImpl(cls); } diff --git a/platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java b/platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java index bd9172362..4537f2ea7 100644 --- a/platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java +++ b/platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java @@ -117,9 +117,6 @@ public class PlatformGenerator implements Generator, Injector, DependencyPlugin .appendMethodBody(method.getReference()).append(";").softNewLine(); } } - writer.appendMethodBody(Platform.class, "newInstance", PlatformClass.class, Object.class).ws().append('=').ws() - .appendMethodBody(Platform.class, "newInstanceImpl", PlatformClass.class, Object.class) - .append(";").softNewLine(); } private void generateNewInstance(GeneratorContext context, SourceWriter writer) throws IOException {