Ich möchte die Instanz dieses Interface KotlinDecompilerService
https://github.com/JetBrains/kotlin/blob/master/idea/src/org/jetbrains/kotlin/idea/internal/KotlinDecompilerService.kt in Groovy bekommen.Probleme beim Zugriff auf das Kotlin Companion-Objekt in Groovy?
Ich versuche:
final KotlinDecompilerService decompilerService =
KotlinDecompilerService.Companion.getInstance()
Aber die Groovy KotlinDecompilerService.Companion
gibt eine java.lang.Class
Instanz. (Das statische Feld und die Klasse haben die gleichen Namen Companion
)
2017-06-24 23:31:59,066 [9849885] ERROR - llij.ide.plugins.PluginManager - Cannot cast object 'class org.jetbrains.kotlin.idea.internal.KotlinDecompilerService$Companion' with class 'java.lang.Class' to class 'org.jetbrains.kotlin.idea.internal.KotlinDecompilerService$Companion'
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'class org.jetbrains.kotlin.idea.internal.KotlinDecompilerService$Companion' with class 'java.lang.Class' to class 'org.jetbrains.kotlin.idea.internal.KotlinDecompilerService$Companion'
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:603)
Ich habe Reflexion zu verwenden, um die Instanz zu erhalten.
final KotlinDecompilerService decompilerService =
KotlinDecompilerService.Companion.newInstance().getInstance()
Es funktioniert, aber ich frage mich nur, ob es einen besseren Weg gibt.
Danke für Ihre Antwort, aber es funktioniert einfach nicht. Vielleicht in Java, das funktioniert. Aber Groovy ist anders. – aristotll
Nur so konnte ich auf das Companion-Objekt von Groovy zugreifen. In meinem Fall war der Fehler 'groovy.lang.MissingMethodException: Keine Signatur der Methode: Foo() ist für Argumenttypen anwendbar –