Kotlin基础2

class Contact(val id:Int,var email: String = "[email protected]")
{
    val category:String = "work"
    fun info()
    {
        println("id:$id email: $email")
    }

}
data class User(val name:String,val id:Int)
fun main()
{
//    val contact = Contact(1,"[email protected]")
//    println(contact)
//    val user = User("aa",11)
//    println(user)
//    val secondUser = User("Alex",1)
//    println("user == secondUser: ${user == secondUser}")
//    println(user.copy("Max"))
//    var nullable:String? = "You can keep a null here"
//    nullable = null
//    println(nullable)
    println(describeString("abc"))
}
fun describeString(maybeString:String?):String
{
    if(!maybeString.isNullOrEmpty())
    {
        return "String of length ${maybeString.length}"
    }else{
        return "Empty or null string"
    }
}

你可能感兴趣的:(kotlin,java)