码迷,mamicode.com
首页 > 其他好文 > 详细

kotlin语法

时间:2017-07-03 10:19:31      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:person   imp   print   val   pen   pack   list   http   org   

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语法

标签:person   imp   print   val   pen   pack   list   http   org   

原文地址:http://www.cnblogs.com/xuejianxiyang/p/7109520.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!