class Layout() {
// Property
var name = "name"
val age: Int
// Initializer block
init {
age = 20
}
// Secondary constructors
constructor(_name: String) : this() {
name = _name
}
// Companion object
companion object {
private const val CONST_VAL = 5
}
}
순서를 항상 고수
**하라.// normal property and local variable
fun processDeclarations() { /*...*/ }
var declarationCount = 1
// Factory function
interface Foo { /*...*/ }
class FooImpl : Foo { /*...*/ }
fun Foo(): Foo { return FooImpl() }
Property 이름
// constants
const val MAX_COUNT = 8
// top-level or object val
object {
val USER_NAME_FIELD = "UserName"
}
// mutable data를 가지는 top-level or object property
val mutableCollection: MutableSet<String> = HashSet()
// singleton 객체 참조하는 property
val PersonComparator: Comparator<Person> = /*...*/
Test methods 이름