Kotlin生成通用的Java代码

我有一个kotlin接口,看起来像这样 interface BaseDao<in M : Model> { … @Delete fun delete(models: Collection<M>) … } 现在当我看到生成的代码,我看到这样的东西: public interface BaseDao { … @Delete void delete(@NotNull Collection var1); … } 有没有办法告诉科特林,我想明确设置集合的类型?

Kotlin对象表达式:比较例子

这段代码基本上按降序对数组进行排序: val arrayList = arrayListOf(1, 5, 2) Collections.sort(arrayList, object : Comparator<Int> { override fun compare(x : Int, y: Int) = y – x }) 如何在世界上压倒y – x作品的比较方法? Kotlin如何知道y – x意味着如果y < x ?

Kotlin HTML-Builder

在Kotlin页面中 ,在HTML-Builder我可以看到下面的代码,我怎样才能在简单的.tk文件中使用它? 这里怎么开始? val data = mapOf(1 to "one", 2 to "two") createHTML().table { for ((num, string) in data) { Iterate over data tr { Functions to create HTML tags td { +"$num" } td { +string } } } }

在Kotlin中实现链表

我最近开始学习Kotlin,所以我决定在其中实现一些数据结构。 所以,我试着实现一个单独的链表: package datastructures public class LinkedList { private data class Node(var nodeValue: Int, var next: Node? = null) private var head: Node? = null fun insert(n: Int) { if(head == null) head = Node(n) else { var cur = head while(cur?.next != null) { cur = cur?.next } cur?.next = Node(n) } } fun […]

无法运行O'Reilly – Kotlin编程简介中所示的hello world应用程序

我试图从O'Reilly视频复制hello world程序 – Kotlin编程入门(Kotlin应用程序的结构)。 这是程序(Main.kt): package com.hadihariri.kotlincourse fun main(args: Array<String>) { println("Hello World!") } 编译“kotlinc Main.kt” 视频显示了这种方式来运行它: java -cp .:<path to kotlin runtime>/kotlin-runtime.jar com.hadihariri.kotlincourse.MainKt 对我来说是: java -cp .:~/.sdkman/candidates/kotlin/current/lib/kotlin-runtime.jar com.hadihariri.kotlincourse.MainKt 运行时确实存在于该位置: ls -al ~/.sdkman/candidates/kotlin/current/lib/kotlin-runtime.jar -rw-r–r– 1 user user 879182 Jun 8 18:23 /home/user/.sdkman/candidates/kotlin/current/lib/kotlin-runtime.jar 但是,如果没有在类路径中指定运行时,将得到相同的错误: java -cp .:~/.sdkman/candidates/kotlin/current/lib/kotlin-runtime.jar com.hadihariri.kotlincourse.MainKt Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics at com.hadihariri.kotlincourse.MainKt.main(Main.kt) […]

在kotlin中的基本功能

寻找一种方法来获得初等职能及其衍生工具我这样做: abstract class Fun() { /** * i = 0 — the function itself, * i = 1, 2, 3, … — its successive derivatives */ abstract fun d(i: Int, x: Float): Float } class Lin(val k: Float) : Fun() { // y = k*x override fun d(i: Int, x: Float, p: Float) = when […]

等同于在kotlin上实现java接口

我是Kotlin新手,我想知道如何在kotlin上实现java接口,我在android上使用它, public interface OnClickedItemListener { void onClick(boolean state); } OnClickedItemListener是我的自定义接口,我想在kotlin中实现,我有这个类: class MyProgressView : RelativeLayout { constructor(context: Context?) : super(context) { init() } constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) { init() } constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { init() } private fun init() { LayoutInflater.from(context).inflate(R.layout.download_progress_layout, this) cusotmView.setOnClickListener { } } […]

编译IntelliJBehave时找不到Kotlin类

我正在尝试编译IntelliJBehave以添加对scala的支持。 当我编译时,我得到以下错误: /home/hobbitProg/devWorkspace/IntelliJBehave/src/com/github/kumaraman21/intellijbehave/kotlin/psi/NavigableKotlinPsiAnnotation.kt Error:(5, 22) Kotlin: Unresolved reference: kotlin Error:(12, 21) Kotlin: Unresolved reference: JetElement /home/hobbitProg/devWorkspace/IntelliJBehave/src/com/github/kumaraman21/intellijbehave/kotlin/psi/NavigableKotlinPsiElement.kt Error:(6, 22) Kotlin: Unresolved reference: kotlin Error:(13, 33) Kotlin: Unresolved reference: JetElement Error:(22, 34) Kotlin: Unresolved reference: JetElement /home/hobbitProg/devWorkspace/IntelliJBehave/src/com/github/kumaraman21/intellijbehave/kotlin/psi/NavigableKotlinPsiMethod.kt Error:(5, 22) Kotlin: Unresolved reference: kotlin Error:(12, 21) Kotlin: Unresolved reference: JetElement /home/hobbitProg/devWorkspace/IntelliJBehave/src/com/github/kumaraman21/intellijbehave/kotlin/support/services/KotlinAnnotationsLoader.kt Error:(8, 22) Kotlin: Unresolved reference: kotlin Error:(9, […]

Kotlin用Android构建问题

将Kotlin集成到一个使用multidex的大型项目中。 所以当我尝试构建时,我得到这个错误: :incrementalDesygnerDebugJavaCompilationSafeguard UP-TO-DATE :compileDesygnerDebugKotlin WARN: Failed to initialize native filesystem for Windows java.lang.RuntimeException: Could not find installation home path. Please make sure bin/idea.properties is present in the installation directory. 路径似乎正确配置和idea.properties文件似乎在那里: C:\Program Files\Android\Android Studio\bin\idea.properties 建筑物需要几分钟才能停下来,所以我从Windows的任务管理器手动停止。 当我重试 – 构建成功! 但是,当我改变一条线,并重建它再次显示相同的错误。 有时我也会得到这个: The system is out of resources. Consult the following stack trace for details. java.lang.OutOfMemoryError: PermGen […]

在类路径中使用Kotlin运行时库执行Java和Kotlin程序

我在eclipse中创建了一个混合项目Java + Kotlin。 我添加了kotlin插件来日食,并添加kotlin性质的项目。 没有问题编译或与Maven建设。 当我执行该项目时,我得到一个异常,因为kotlin运行时jar不在那里。 没有问题了,我在运行配置中手动添加了jar,如下所示: 但是这是一个黑客。 任何人都可以告诉我最优雅的方式来告诉eclipse当我执行程序时添加eclipse kotlin插件所使用的相同的运行时,这样如果我更新插件,运行时jar将保持同步。 如果有帮助的话,这就是库在项目构建路径中的样子: 这似乎很简单,但我无法找到正确的方法来做到这一点…