Kotlin第三章

Kotlin 第三章

Kotlin 是一种在 Java 虚拟机上运行的静态类型编程语言,被称之为 Android 世界的Swift,由 JetBrains 设计开发并开源。
Kotlin 可以编译成Java字节码,也可以编译成 JavaScript,方便在没有 JVM 的设备上运行。
在Google I/O 2017中,Google 宣布 Kotlin 成为 Android 官方开发语言。

Kotlin 的一些基本方法 以及函数

 package com.example.test710

import android.support.v7.app.AppCompatActivity
import android.os.Bundle


fun  main(Args:Array<String>){

    // println(sum(1,2));
    // println(Maxof(300,100))
   //   println(maxof2(500,100))
   //   println(forin())
   //  println( When(1))

}

fun sum(a:Int,b:Int):Int{  //TODO 返回值为int类型的方法

    return  a+b;
}

fun String(){ //TODO 字符串$拼接
    var a=1
    var b="a is $a"
    println(b)
}


fun Maxof(a:Int,b:Int):Int{  //TODO 条件表达式

    if(a>b){
        return  a
    }else {
        return  b
    }
}

fun maxof2(a:Int,b:Int)=if(a>b)a else b  //TODO if表达式

fun forin(){  //TODO for 循环

    var items= listOf<String>("斯蒂芬库里","詹姆斯哈登","保罗乔治","德里克罗斯")
    //TODO for in
//    for(i in items){
//        println(i)
//    }

    //TODO foreach
    items.forEach {
        println(it)
    }



}

 var call : callBack=object : callBack{
    override fun show(a: Int) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

}

interface callBack{
    fun show(a:Int)
}


class Mycall: callBack{
    override fun show(a: Int) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

}

fun When(a:Int){  //TODO When 用法

    when(a){
        1 -> "是1"
        2 -> "是2"
        3 -> "是3"
        else ->"是其他"             
    }

}

object Resource{  //TODO 创建单例
    val name="Name"
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值