为什么我的代码无法访问?
我是Kotlin的新手,想写一个家谱程序,但是我得到一个错误:
Warning:(30, 14) Kotlin: Parameter 'args' is never used Warning:(32, 9) Kotlin: Unreachable code
我该如何解决?
data class Person( val id: Int, val name: String ) { fun main(args: Array<String>) { val person = Person(1, "Nikolay") println("my name is ${person.name}") } }
我无法弄清楚如何使它工作。
哇,它的作品!
data class Person( val id: Int, val name: String, val gender: Int, val father: Int, val mother: Int, val children: List<Int>, val email: String, val homepage: String, val date_of_birth: String, val date_of_death: String, val is_living: Boolean, val place_of_birth: String, val place_of_death: String, val cemetery: String, val schools: List<String>, val jobs: List<String>, val work_places: String, val places_of_living: String, val general: String, val default_picture: String ) fun main(args: Array<String>) { val person =Person(1, "Nikolay", 1, 10, 11, listOf(2), "mi@ya.ru", "mishin.narod.ru", "07.02.1976", "", true, "Moscow", "", "", listOf("780", "MIIT"), listOf("luxoft", "lotus domino"), "Nagornaya", "Buninskaya Alleya", "perl and kotlin programmer", "") println("my name is ${person.name}") }
还有问题用日期时间怎么用呢? 它支持Kotlin吗?
如果要在main方法中创建Person的新实例,则需要将主函数从类中移出到包级别:
data class Person( val id: Int, val name: String ) fun main(args: Array<String>) { val person = Person(1, "Nikolay") println("my name is ${person.name}") }
现在你可以玩Kotlin。