Hello World With Kotlin
2017-05-25 11:33
274 查看
Kotlin 和 Java 一样,可以在PC上运行,可以用IDEA进行开发,环境配置参考Getting Started with IntelliJ IDEA。
官方提供了一个学习网站,可以运行一些例子Kotlin。
也可以通过命令行的方式编译运行,参考Working with the Command Line Compiler
如上,是一个最简单的 Hello World。
Kotlin兼容Java,可以直接调用Java代码;
与Java相比,行结束不需要分号;
包定义和import语句跟Java一样;
变量的定义,” 变量: 类型 “ 的形式,如 savedInstanceState: Bundle?(?表示变量可为null);
函数定义以 fun 开头, 如 fun test(arg: String): Int;
类定义以 class开头,如 class MainActivity : AppCompatActivity()。
*
参考*
Getting Started with IntelliJ IDEA
Working with the Command Line Compiler
官方提供了一个学习网站,可以运行一些例子Kotlin。
也可以通过命令行的方式编译运行,参考Working with the Command Line Compiler
PC
fun main(args: Array<String>) { println("Hello, World!") }
如上,是一个最简单的 Hello World。
Android
package com.hello.test import android.support.v7.app.AppCompatActivity import android.os.Bundle import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) textView.text = "Hello World!" // same ass textView.setText() } }
入门
Kotlin代码文件以.kt后缀,源代码所在的目录结构不必与包结构保持一致,但最好和Java一样,目录和包名一致。Kotlin兼容Java,可以直接调用Java代码;
与Java相比,行结束不需要分号;
包定义和import语句跟Java一样;
变量的定义,” 变量: 类型 “ 的形式,如 savedInstanceState: Bundle?(?表示变量可为null);
函数定义以 fun 开头, 如 fun test(arg: String): Int;
类定义以 class开头,如 class MainActivity : AppCompatActivity()。
*
参考*
Getting Started with IntelliJ IDEA
Working with the Command Line Compiler
相关文章推荐
- Android Studio 下的Kotlin HelloWorld
- Spring 3 mvc hello world application with maven and jstl
- Kotlin Hello World For Android
- (转) Eclipse - Python - Installation of PyDev with a Python Hello World tutorial
- Hello World with Ant
- HelloWorld with Java, iOS and RoboVM
- Kotlin入门教程系列(一)Kotlin HelloWorld
- Objective-C 2.0 with Cocoa Foundation --- 2,从Hello,World!开始
- Hello World by Adam Ge with Python
- Hello world with LUA
- the first helloworld with j2me
- CentOS 7 之Helloworld with c
- iOS Dev (2) HelloWorld with .xib
- JAXB - Hello World with Namespace
- CentOS 7 之Helloworld with c
- Hello World Kotlin
- iOS Dev (3) HelloWorld with codes
- Hello world with LUA
- Tutorial: Hello World with Apache Ant
- 《Springboot极简教程》 Springboot plus Kotlin :Hello,World