val adapter = ItemAdapter() val listView by lazy { (findViewById(R.id.listView) as ListView) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_sample) listView.adapter = adapter } }
Message class User(val name: String, val age: Int) { fun vaildate(): Boolean { return name.length in 1..16 && name in listOf("hoge","foo") && age >= 20 } }
Validation͕૿͑ͯͳ͠ • υϝΠϯͷจ๏ͷ··ͰɺಡΈ͍͢ class User(val name: String, val age: Int) { val validation = Validation<User> { be { age >= 20 } not "成人のみです" be { name.length in 1..16 } not "1-16文字以下で" be { name !in listOf("hoge", "foo") } not "NGワード以外で" } fun vaildate() = validation.validate(this) }
Int) { val validation = Validation<User> { of(age) be { it >= 20 } not "成人のみです" of(name) be { it.length in 1..16 } not "1-16文字以下で" of(name) be { it !in listOf("hoge", "foo") } not "NGワード以外で" } fun vaildate() = validation.validate(this) }
Any?, property: KProperty<*>): String { return "$thisRef, thank you for delegating '${property.name}' to me!" } operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String) { println("$value has been assigned to '${property.name} in $thisRef.'") } } class Example { var hoge: String by Delegate() }