Learn OOP in Kotlin
-
Gradle
- Kotlin file, doesn’t need package folder structure.
- no
newneeded - String reference variables by
$varin double quote - modifier
publicis default in Kotlin, instead needingprivatekeyword to explicitly. - method keyword
fun - arguments
name: Type - modifier
internalvisible to collection of files inprojectscope; or mavenmodules - mutable vs immutable variable:
varvsval - mutable properties
-
property set/get
- primary constructor
- secondary constructor
default arguments
initblock
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