Tag: 互操作

我怎样才能引用从Java的伴侣对象?

我有一个混合的项目, Java和Kotlin类,我想知道如何从我的Java类引用companion objects 。

在Java中使用Kotlin类:找不到符号

我已经find了关于Android的这个类似的问题,但我使用普通的Java与Maven作为构建工具。 我认为最好发表一个新的问题。 我创建了一个Kotlin类,我试图从Java类MyKotlinClass.class 。 Maven构建失败,而IntelliJ Idea中的编译工作正常。 我已经将Kotlin插件添加到maven: org.jetbrains.kotlin kotlin-maven-plugin ${kotlin.version} compile compile compile test-compile test-compile test-compile 但是这并没有帮助: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project app: Compilation failure [ERROR] MyClassLinkingKotlin.java:[100,40] error: cannot find symbol 行/列恰好引用符号MyKotlinClass.class 。 即使是这样使用也会失败: System.err.println(MyKotlinClass.class)

如何用Kotlin interop强制执行generics

我在Kotlin中有一个方法,它返回一个通用列表的Rx Observable: public fun getObservable(): Observable<List> { return Observable.just(theList) } 因为Kotlin列表特征定义为List ,所以Java会将返回types看作Observable<List> Observable<List> 。 有没有办法告诉Kotlin编译器,Java应该将这个视为Observable<List> ? http://kotlinlang.org/docs/reference/generics.html 已更新为正确显示问题。