Swotger为Kotlin

有没有人用Kotlin使用了一个夸大的工具? 在我们的组织中,我们使用Java和SpringMVC(@RestController类)创建了大部分REST服务。 我们使用springfox来生成Swagger API文档。 Swagger JSON表示也用于自动提供可搜索的服务目录,所以服务元数据的swagger格式对我们来说非常重要。 一些开发团队现在开始使用Kotlin。 我们正在寻找与使用KOTLIN的springfox或其他swagger库有关的建议或意见。

如何指定Kotlin版本?

我想用Kotlin 1.0.4编译我的Kotlin程序。 什么是这个目的正确的命令行选项? 我听说过 – 版本选项,但不知道如何使用它。 -version 1.0.4不起作用。

NullPointerException在Kotlin中

当我在kotlin活动中编写此代码时 var tv: TextView = findViewById(R.id.tv_kotlin) as TextView 它总是与以下错误崩溃: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference 当我将Java代码转换为kotlin代码时,auto转换器总是这样做: private var btn: Button? = null 而当我使用的参考,我必须把! 背后它使代码真丑。那么在kotlin android绑定UI的正确方法是什么? 完成的代码: class JavaToKotlinActivity : AppCompatActivity() { private var tv: TextView = findViewById(R.id.tv) as TextView private var btn: Button? = null private […]

Android Studio 3 / Kotlin代码覆盖

我的Android应用程序是多模块项目: include (android-app/kotlin-android)':application', (pure kotlin)':presentation', (pure kotlin)':domain', (android-library/kotin-android)':dataproviders' 我正在使用Junit / Mockito进行测试,并且只有为kotlin android模块生成代码覆盖的问题。 经过测试的行对于android studio是可见的。 在ui.viewmodel包中测试类: 但是,对于纯粹的kotlin (例如,域,演示)测试覆盖工作正常: 我正在使用Android Studio 3.0 Canary 8您可以在github上查看我的build.gradle文件: 的build.gradle dependencies.gradle application.build.gradle presentation.build.gradle Android应用程序模块中的示例测试: MostPopularViewModelTest 纯kotlin模块中的示例测试: MostPopularPresenterTest 有人可以帮我解决我的问题吗? 我尝试通过Jacoco生成代码覆盖,但它也没有显示代码覆盖率。

二级构造语法kotlin

我有一个主要的构造函数下面的kotlin类, class Person(first: String, last: String, age: Int){ init{ println("Initializing") } } 我想添加一个二级构造函数,将全名解析为名和姓,并调用主构造函数。 但是,我不能得到正确的语法… class Person(first: String, last: String, age: Int){ // Secondary constructor constructor(fullname: String, age: Int): this("first", "last", age) { println("In secondary constructor") } init{ println("Initializing") } } 这工作正常,因为我没有实际解析二级构造函数中的fullname 。 当我继续尝试解析全名时, constructor(fullname: String, age: Int): var first = fullname.split()[0]; … { println("In secondary […]

Kotlin中的嵌套接口

在Java中,可以在接口中声明接口: …. public @interface NotEmpty { …. public @interface List { NotEmpty[] value(); } } 这个例子来自Hibernate的NotEmpty验证器。 请参阅以下讨论 ,了解这有什么好处。 不幸的是,在Kotlin annotation class不能有一个主体。 Kotlin如何实现嵌套接口?

Java ArrayList到Kotlin数组

有没有简单的方法将Java ArrayList转换为Kotlin数组? 以下代码: fun test(): Array<String> { val elems = ArrayList<String>() return elems.toArray() } 给出错误: main.kt:2:15: error: unresolved reference: ArrayList val elems = ArrayList<String>() ^ 我正在解析一些JSON,不知道有多少元素,但是一旦我读了它们,我不需要以任何方式修改数据,所以我想我会去Kotlin数组作为数据类型。

Kotlin使用Java回调接口

我有一个WebView。 我想打电话 public void evaluateJavascript(String script, ValueCallback<String> resultCallback) 这个方法。 这里是ValueCallback接口: public interface ValueCallback<T> { /** * Invoked when the value is available. * @param value The value. */ public void onReceiveValue(T value); }; 这是我的kotlin代码: webView.evaluateJavascript("a", ValueCallback<String> { // cant override function }) 任何人有想法重写kotlin的onReceiveValue方法? 我试过“转换Java到Kotlin”,但结果是下一个: v.evaluateJavascript("e") { } 谢谢!

从Java到Kotlin

我正在努力将用Java编写的简单的JavaFX calc转换成Kotlin代码。 https://gist.github.com/jewelsea/4344564 – > java源码。 我在Kotlin翻译的是: import Model.Math import javafx.application.Application import javafx.beans.binding.Bindings import javafx.beans.property.* import javafx.event.ActionEvent import javafx.event.EventHandler import javafx.geometry.Pos import javafx.scene.Scene import javafx.scene.control.* import javafx.scene.input.KeyEvent import javafx.scene.layout.* import javafx.stage.Stage import javafx.stage.StageStyle import java.util.HashMap // A simple Kotlin, JavaFX application class KotlinCode : Application() { private val accelerators = HashMap<String, Button>() private val stackValue […]

Kotlin协同程序如何比RxKotlin更好?

我为什么要使用Kotlin协同程序? RxKotlin库似乎更为复杂。 Kotlin协同程序看起来不那么强大,而且比较麻烦。 我根据安德烈·布雷斯拉夫(JetBrains)的这个设计演讲,在协同工作的基础上: https : //www.youtube.com/watch?v = 4W3ruTWUhpw 幻灯片从谈话是可以访问这里: https : //www.slideshare.net/abreslav/jvmls-2016-coroutines-in-kotlin