Tag: intellij idea

有什么简单的方法来看看Kotlin函数抛出什么异常?

我主要了解检查异常的潜在问题,以及Kotlin忽略它们的原因。 然而,我遇到的问题是我找不到任何清楚地向调用者指出函数可能抛出什么异常的万无一失的方式。 我已经在Python中遇到了无数次的问题,我的程序在运行好几个月后会崩溃,因为我没有意识到我正在使用某个库的函数会引发特定的异常。 尽管被迫捕捉异常可能是相当有问题的,但是清楚地看到函数可能抛出的所有可能异常是很好的。 所以回到这个问题,有什么简单的方法来看看函数在Kotlin中抛出什么异常? 那么从Kotlin调用Java编写的方法呢? 即使只是在工具(intelliJ)。 我不想把它写在javadoc或kdoc中,因为你正在使用的函数的编写者可能会忽略它。

如何将java jna接口转换为kotlin

我正试图移植到kotlin的openvr绑定 我有以下在Java中: public class IVRSystem extends Structure { /** * C type : GetRecommendedRenderTargetSize_callback* */ public IVRSystem.GetRecommendedRenderTargetSize_callback GetRecommendedRenderTargetSize; public interface GetRecommendedRenderTargetSize_callback extends Callback { void apply(IntBuffer pnWidth, IntBuffer pnHeight); }; } Intellij将其自动转换为 var GetRecommendedRenderTargetSize: IVRSystem.GetRecommendedRenderTargetSize_callback? = null interface GetRecommendedRenderTargetSize_callback : Callback { fun apply(pnWidth: IntBuffer, pnHeight: IntBuffer) } 我改变它然后: fun getRecommendedRenderTargetSize(pnWidth: IntBuffer, pnHeight: IntBuffer) = […]

IntelliJ Idea for Kotlin @ConfigurationProperties类中不生成spring-configuration-metadata.json文件

我试图为我的基于Spring Boot的项目生成spring-configuration-metadata.json文件。 如果我使用Java @ConfigurationProperties类,它会自动正确生成: @ConfigurationProperties("myprops") public class MyProps { private String hello; public String getHello() { return hello; } public void setHello(String hello) { this.hello = hello; } } 但是,如果我使用Kotlin类,则不会生成spring-configuration-metadata.json文件(我已经尝试了gradle build和Idea Rebuild Project )。 @ConfigurationProperties("myprops") class MyProps { var hello: String? = null } AFAIK Kotlin与构造函数,getter和setter生成相同的类,并且应该像普通的Java bean一样。 任何想法为什么春季启动配置处理器不适用于Kotlin类?

我如何知道Kotlin的推断类型?

(我使用Kotlin 1.1.2-2) 例如,如何知道表达式的推断类型if (boolean_value) 1 else 2.0 ? kotlinc-jvm不显示类型。 javaClass也没有帮助,因为它显示计算值的类型而不是表达式。 >>> (if (true) 1 else 2.0).javaClass.name java.lang.Integer >>> (if (false) 1 else 2.0).javaClass.name java.lang.Double >>> val v: Double = if (false) 1 else 2.0 error: the integer literal does not conform to the expected type Double val v: Double = if (false) 1 else 2.0 […]

kotlin项目不能在gradle中建立(找不到参考)

我有一个java项目写在kotlin,我使用intelliJ IDEA来开发这个项目。 我有依赖关系设置(多个项目)的麻烦。 我已经阅读了大量的例子,但是我找不到解决方法,这里是我的依赖设置代码,它可以正确的在java类中构建,但是kotlin类会得到很多错误'Unresolved reference'。 对于我的设置是否有任何错误或gradle是不适合与kotlin。 PS:当我只构建核心项目时,构建过程会成功,但是在测试项目中构建会得到参考未解决的错误 以下是build.gradle的代码。 allprojects { apply plugin: 'java' apply plugin: 'kotlin' group 'TestProject' version '1.0'} subprojects{ apply plugin: 'java' apply plugin: 'kotlin' def defaultEncoding = 'UTF-8' compileJava.options.encoding = defaultEncoding sourceCompatibility = 1.8 targetCompatibility = 1.8 repositories { mavenCentral() mavenLocal()} dependencies { // Kotlin compile "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" testCompile […]

kotlin在委托中只有一个继承的方法的未解决的参考

我有一个通过方法提供一些代表的科林类。 编译一切时,我得到错误 错误:(121,30)Kotlin:未解析的引用:stringSet 请注意,所有其他方法工作得很好,它编译每一个这种方法的发生 以下是提供代表的课程片段: //Compiles and can be accessed protected fun int(default: Int? = null, jsonName: String? = null, jsonObject: JsonObject = configJson) = JsonProperty({it?.asInt}, jsonName, jsonObject, default.toStringOrNull()) //compiles, but can't be accessed in one class protected fun stringSet(jsonName: String? = null, jsonObject: JsonObject = configJson, default: Set<String>? = null): JsonProperty<MutableSet<String>> { return JsonProperty<MutableSet<String>>({ […]

将kotlin库(不是Android)发布到jCenter

我有Intellij Idea 2016.1 gradle-application(不是Android)写在Kotlin。 我需要将它放在jCenter中,并作为依赖项添加到Android应用程序中。 我找不到任何有关它的信息。 所有引用都涉及Android项目。 我不知道如何做到这一点。 寻找详细的说明

Kotlin android扩展,软件包不能被导入

我安装了最新的Kotlin安卓扩展插件(版本1.0.0-beta-1103),并将类路径添加到我的Gradle依赖项中。 它编译,但我仍然无法导入我的android片段内的包。

Kotlin测试失败从命令行与ClassNotFoundException但从IntelliJ工作

我在这里有一个Kotlin Spring Boot项目。 它有一些测试,从IntelliJ运行得很好,但是当我从命令行运行,失败,出现以下错误。 BUILD FAILED in 1m 12s 7 actionable tasks: 7 executed asarkar:license-report-kotlin$ ./gradlew clean test > Task :compileKotlin Using kotlin incremental compilation > Task :compileTestKotlin Using kotlin incremental compilation > Task :test 2017-07-16 21:43:06.345 INFO 2956 — [ Thread-13] scaAnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@54fa5525: startup date [Sun Jul 16 21:42:04 PDT 2017]; root […]

在Idea中Kotlin脚本文件的语法高亮

我移植了我的Gradle项目配置Kotlin脚本的用法:现在我有build.gradle和build.gradle.kts并可以切换他们配置settings.gradle : project(':myProject').buildFileName='build.gradle.kts' 问题是kts build.gradle.kts不正确highlited:它不能解决依赖关系,说version = 123不是一个有效的单词等等。 我使用Idea Ultimate 2017.1.3和kotlin-plugin 1.1.2。 什么问题? 删除build.gradle也没有帮助。 gradle-script-kotlin项目文件正确地被高亮显示 。