Cui
Cui The CUI of TechCui

Learn OOP in Kotlin

Learn OOP in Kotlin
  • Gradle

  • Kotlin file, doesn’t need package folder structure.
  • no new needed
  • String reference variables by $var in double quote
  • modifier public is default in Kotlin, instead needing private keyword to explicitly.
  • method keyword fun
  • arguments name: Type
  • modifier internal visible to collection of files in project scope; or maven modules
  • mutable vs immutable variable: var vs val
  • mutable properties
  • property set/get

  • primary constructor
  • secondary constructor default arguments init block
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Meeting {
    fun addParticipant(participant: Participant) {
        println(participant.email)
    }    
}
class Participant {
    var name = ""
    var email = ""
    val canonicalEmail: String
        get() = email.toUpperCase()
        set(value: String) {
            println(value)
        }

}

Runner.kt



comments powered by Disqus