相关文章
更多最近更新
更多Kotlin 基于Eclipse 的入门示例
2019-04-21 23:57|来源: 网路
Eclipse 通过 Marketplace 安装 Kotlin 插件,打开 Eclipse,选择 Help -> Eclipse Marketplace… 菜单,搜索 Kotlin 插件:
然后重启 Eclipse 选择 Window -> Open Perspective -> Other...,如果看到了 Kotlin 选项表明安装成功。
创建新项目
选择 File -> New -> Kotlin Project 来创建 Kotlin 项目:
创建成功后,项目结构如下:
接下来 我们点击 src 文件夹,创建一个 Kotlin 文件,不用写 ".kt" ,默认自动添加,它可以任意命名,这里我们创建 hello
接下来,我们在 hello.kt 文件中写点代码。Eclipse 为我们提供了一个快速完成此操作的模板,只需键入 main 然后按 Enter 即可。
运行应用
接下来我们在 hello.kt 的编辑框内右击鼠标选择 Run As -> Kotlin Application 即可运行:
运行成功后就可以在窗口 Console 中看到结果。
这样我们第一个 Kotlin 代码就运行起来了。
相关问答
更多-
android 3d游戏开发 所需要的软件[2023-10-23]
eclipse -
安卓应用程序开发使用哪个开发工具最好?[2022-11-21]
eclipse -
安卓手机编程现在用什么软件?并求下载地址。[2022-05-06]
eclipse -
Kotlin - 错误:无法找到或加载主类_DefaultPackage(Kotlin - Error: Could not find or load main class _DefaultPackage)[2023-03-05]
这是在插件版本0.4.0中自动生成启动配置的严重错误( KT-10221 )。 它固定在0.5.0,所以推荐解决方法是更新插件。 问题的根源在于插件使用旧模式来为Kotlin编译器放弃的main函数生成类的名称。 可以通过手工编辑启动配置( Eclipse Menu - > Run - > Run Configurations ... )并更改Java Application组中的Main class字段来解决此问题 。 如果文件名为hello.kt且没有包指令(如教程中所述),则更正的字符串应该是Hell ... -
官方Gradle Kotlin DSL存储库包含一个基本的Kotlin / JS示例: https : //github.com/gradle/kotlin-dsl/tree/master/samples/hello-js The official Gradle Kotlin DSL repository contains a basic Kotlin/JS sample: https://github.com/gradle/kotlin-dsl/tree/master/samples/hello-js
-
为什么println()只执行一次? 发生这种情况是因为第一次访问它时,它会被创建。 要创建它,它会调用你只传递一次的lambda,并赋值"my lazy" 。 您在Kotlin编写的代码与此Java代码相同: public class LazySample { private String lazy; private String getLazy() { if (lazy == null) { System.out.println("comput ...
-
在使用以下消息深入org.eclipse.jetty.websocket.common.events.annotated.CallableMethod类内部的closed方法调用期间出错: 指定为非null的参数为null:方法webchat.WSHandler.closed,参数原因 它与Kotlin的可空性功能有关,当您使用下面的签名声明您的方法时,一切正常: fun closed(session: Session, statusCode: Int, reason: String?) There is ...
-
如果您使用start.spring.io项目生成器( 切换到完整版 ),您可以选择spring boot 2 snapshot和kotlin作为语言。 适用于基于maven和gradle的构建。 一切都在那里。 那应该是一个很好的起点:) if you use the start.spring.io project generator (switch to the full version) you can choose spring boot 2 snapshot and kotlin as a lang ...
-
您需要使用JDK 8运行Kotlin。1.安装jdk 8。 sudo apt-get install openjdk-8-jdk Windows - > Preference - > Java - > Installed JREs单击add ,然后添加Standard VM - >编写您的jdk路径 - >并为Default VM arguments写入-Xmx512m -ea -Djava.awt.headless = true - > Finish - > Apply and Close 右键单击您的 ...
-
在Kotlin进行JUnit测试(JUnit test in Kotlin)[2022-05-23]
JUnit不在您的项目类路径中,因此IntelliJ无法找到它的包。 按照本答案中列出的步骤: 正确的方法将外部jar(lib / * .jar)添加到IntelliJ IDEA项目 ,选择库,然后选择junit。 JUnit isn't in your project classpath, so IntelliJ can't find it's packages. Follow the steps outlined in this answer: Correct way to add external j ...