kotlin语法
Posted Ace007
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kotlin语法相关的知识,希望对你有一定的参考价值。
https://try.kotlinlang.org/#/Examples/Hello,%20world!/Simplest%20version/Simplest%20version.kt
/**
* We declare a package-level function main which returns Unit and takes
* an Array of strings as a parameter. Note that semicolons are optional.
*/
fun main(args: Array<String>) {
var c=do1(1);
println("Hello, world!"+c)
var list=listOf(1,2,3,5,7)
for(i in list){
println(i);
}
}
fun do1(a:Int):Int
{
for(i in 1..5)
println(a.toString()+"2");
return a;
}
//类 继承
fun main(args: Array<String>) {
println("Hello, world!")
var tom= student("tom",21);
println(tom.pname+\'|\'+tom.age);
var jay=teacher("jay",33);
println(jay.name+\'|\'+jay.age);
}
open class person(var name:String){
public var pname=name;
}
class student(name:String,age:Int):person(name){
public var age=age;
//注释
/*注释
2*/
}
data class teacher(var name:String,val age:Int)
//接口
fun main(args: Array<String>) {
println("Hello, world!")
var ap=mp3Player();
ap.play("beat it");
}
interface play{
fun play(name:String);
}
class mp3Player:play{
override fun play(name:String){
println("playing:"+name);
}
}
From:http://www.cnblogs.com/xuejianxiyang/p/7109520.html
以上是关于kotlin语法的主要内容,如果未能解决你的问题,请参考以下文章