Android kotlin之靜態方法

Java寫法

/**
 * Created by E on 2018/3/7.
 */
public class ILogKo {
    private static String msg = "adb";
    public static String getBrand(){
        return "SAM";
    }
    public static String getLogMsg(){
        return msg;
    }
}
Kotlin寫法
1.
/**
 * Created by E on 2018/3/7.
 */
class ILogKo {

    companion object {
        val logmsg = "adb"

        fun getBrand() : String{
            return "SAM"
        }

        fun getLogMsg() : String{
            return logmsg
        }
    }

}

2.
/**
 * Created by E on 2018/3/7.
 */
object ILogKo {

    val logmsg = "adb"

    fun getBrand() : String{
        return "SAM"
    }

    fun getLogMsg() : String{
        return logmsg
    }

}
調用
ILogKo.getLogMsg()




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章