• 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

  • 相关阅读:
    android音量知识总结
    android设置dialog透明度,黑暗度的方法
    获得图片资源总结
    Fragment使用案例
    activity主窗口与软键盘的交互模式
    AndroidManifest.xml中android:configChanges的简介
    2G,3G和4G网络类型了解
    安卓权限大全
    Spring
    多线程
  • 原文地址:https://www.cnblogs.com/xuejianxiyang/p/7109520.html
Copyright © 2020-2023  润新知