Tag: IntelliJ

为什么kotlin错误:val minT:Long = -9223372036854775808L //Long.MIN_VALUE

Kotlin的Long.MIN_VALUE == -9223372036854775808,但是当我写: val minT: Long = -9223372036854775808L //Long.MIN_VALUE IDEA说这是错的。 Dmitry Jemerov告诉我这是因为Kotlin中的-符号不是恒定值的一部分,而是应用于恒定值的一元减算子,并且9223372036854775808L比Long类型的最大可能正值大1。 但是现在呢,为什么说诠释是对的 val minI: Int = -2147483648 //Int.MIN_VALUE 看这里:

Kotlin – 可能会错误地报告一个未使用的代码

我有我的应用程序中的所有活动的基类。 我想要一个变量activityClass类型为<? extends BaseActivity> <? extends BaseActivity> 。 这就是我在Kotlin中声明的变量: var activityClass = MainActivity::class.java as Class<out BaseActivity> 问题是,在Android工作室我得到的部分“ as Class<out BaseActivity> ”变灰,弹出消息说:“不需要as Class<out BaseActivity> ” 如果我按照AS的建议,我删除了转换,当我尝试使用从BaseActivity派生的其他活动分配变量时,我得到编译器错误。 以下代码: activityClass = SpecificActivity::class.java 给我一个错误“类型推断失败。预期类型不匹配:需要Class<MainActivity> ,找到Class<SpecificActivity> ”。 这主要是因为在提交代码更改时导致问题,因为选中了AS提交向导中的“清理”和“优化导入”选项,从而删除实际使用的“未使用”代码(“作为类”部分)。 解决方案是不要关闭这些选项,因为我真的希望他们被设置为true。 如果我提交了更改,请转到使用该投射的类并撤销更改,它会要求我“在提交之前撤消优化导入?”。 如果我确认了,我会得到这个投射,所以我知道这是造成这个问题的原因。 PS:我使用Kotlin 1.0.5-3

当前选择的Java调试器不支持“Kotlin Line Breakpoints”类型的断点

我有一个基于Java的项目。 我添加了我的第一个Kotlin类。 我把一个断点,并得到了下面的消息。 The currently selected Java debugger doesn't support breakpoints of type 'Kotlin Line Breakpoints'. As a result, these breakpoints will not be hit. The debugger selection can be modified in the run configuration dialog. 我该怎么办?

Kotlin“rem”作为“mod”的替代品不可用?

对于count % 2我收到警告 警告:(137,17)Kotlin:'mod(Int):Int'已被弃用。 使用REM(其他)来代替 而Intellij IDE提供了count.rem(2)的自动更正,然后由于未解决rem引用而被标记为错误。 我究竟做错了什么?

Kotlin koans不工作? 我疯了吗?

Kotlin koan 3,“Default Arguments”,似乎很简单,但我解决不了: fun foo(name: String = "", number: Int = 42, toUpperCase: Boolean = false): String { if(!toUpperCase) return name+number else return name.toUpperCase()+number } fun task3(): String { // todoTask3() return ( foo("a") + foo("b", number = 1) + foo("c", toUpperCase = true) + foo(name = "d", number = 2, toUpperCase = true)) […]

如何在Intellij Idea中运行Kotlin函数

我已经创建了一个测试项目,以IntelliJ IDEA CE中的Kotlin开始。 IDE版本和系统是2017.1.4 Build#IC-171.4694.23,构建于2017年6月6日JRE:1.8.0_112-release-736-b21 x86_64 JVM:由JetBrains sro提供的OpenJDK 64位服务器VM Mac OS X 10.12.4 有一个.kt文件,其中包含一个主要功能。 当我右键点击它,我可以选择运行,但我得到一个错误形式的JUnit:! 预计JUnit版本3.8或更高版本。 我知道这是关于丢失的配置,但是我也不能为Kotlin设置一个适当的配置。 即它需要一个“主类”,我没有。 设置软件包名称,因为一些其他的讨论建议也没有帮助。 在IDEA中Kotlin的适当配置是什么? 谢谢!

在Idea中构建Kotlin项目时,UnsupportedOperationException

当我尝试构建我的Kotlin项目时,我在Idea中得到以下错误 : Error:Kotlin: [Internal Error] org.jetbrains.kotlin.util.KotlinFrontEndException: Exception while analyzing expression at (60,19) in E:/altruix-is/src/main/kotlin/com/mycompany/myproduct/capsulecrm/CapsuleCrmSubsystem.kt: client.execute(req) […] Caused by: java.lang.UnsupportedOperationException: doSubstitute with no original should not be called for synthetic extension at org.jetbrains.kotlin.synthetic.SamAdapterFunctionsScope$MyFunctionDescriptor.doSubstitute(SamAdapterFunctionsScope.kt:165) at org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl$CopyConfiguration.build(FunctionDescriptorImpl.java:553) at org.jetbrains.kotlin.load.java.ErasedOverridabilityCondition.isOverridable(ErasedOverridabilityCondition.kt:47) 错误似乎发生在通话中 res = client.execute(req) client是Apache HttpClient。 源文件可以在这里找到。 我向JetBrains提交了这个错误报告,但是我需要在这个项目上继续工作,因此需要解决。 请注意,直到昨天一切正常。 昨天我把Kotlin插件升级到了最新版本,也许就是这个问题。 我怎样才能避免上面的错误? 更新1(03.03.2017 14:46 MSK): 这不起作用: open fun addNote(note: String, […]

Spring MVC错误404错误的请求Kotlin

我正在使用Kotlin开发Spring MVC应用程序。 我有一个简单的表单,当我提交时,我得到错误404错误的请求 。 我使用的Jetty服务器和Intellij社区版 。我试过调试,但因为我从来没有调试过的Web应用程序,它不是那么有用。 web.xml中 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Archetype Created Web Application</display-name> <servlet> <servlet-name>frontDispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>frontDispatcher</servlet-name> <url-pattern>/springkotlinmvc/*</url-pattern> </servlet-mapping> </web-app> frontDispatcher-servlet.xml中 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context = "http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <context:annotation-config/> <mvc:annotation-driven/> <context:component-scan base-package="org.manya.kotlin"/> <bean id="viewResolver" […]

无法将Kotlin“声明平台类型”警告转换为错误

我有一个简单的Kotlin函数,它正在调用一些Java代码: fun simpleSchema(field: GraphQLFieldDefinition) = newSchema() .query(newObject() .name("root") .field(field) .build()) .build() 在我的IDEA里面,即 IntelliJ IDEA 2016.2.5 Build #IU-162.2228.15, built on October 14, 2016 JRE: 1.8.0_112-release-287-b2 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains sro 有一个有用的信息: Declaration has platform type. Make the type explicit to prevent subtle bugs. This inspection reports functions and properties that have platform […]

Intellij IDEA不会将maven依赖项添加到kotlin脚本类路径中

我想从Intellij Idea运行一个Kotlin脚本,但是在pom.xml中定义的依赖没有被添加到类路径中。 在“ 运行配置”页面上,没有像使用 Kotlin或Java一样使用“模块类路径”选项。 我希望IDE将-classpath参数传递给org.jetbrains.kotlin.cli.jvm.K2JVMCompiler因为如果手动执行,所有工作都正常。 这是一个错误还是我错过了什么? noclasspath.kts import org.slf4j.MDC val osf = MDC.getMDCAdapter() val a = "Monkey" println("$a is big") 的pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0"> <modelVersion>4.0.0</modelVersion> <groupId>org.whatever</groupId> <artifactId>whyunowork</artifactId> <version>1.2.3</version> <properties> <kotlin.version>1.0.4</kotlin.version> </properties> <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.21</version> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>kotlin-maven-plugin</artifactId> <groupId>org.jetbrains.kotlin</groupId> <version>${kotlin.version}</version> <executions> <execution> <id>compile</id> <goals> <goal>compile</goal> </goals> <configuration> <sourceDirs><sourceDir>${project.basedir}/src/main/kotlin</sourceDir><sourceDir>${project.basedir}/src/main/java</sourceDir> </sourceDirs> </configuration> </execution> […]