Learn OOP in Kotlin
![Learn OOP in Kotlin](/assets/images/default.jpg)
-
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 needingprivate
keyword to explicitly. - method keyword
fun
- arguments
name: Type
- modifier
internal
visible to collection of files inproject
scope; or mavenmodules
- mutable vs immutable variable:
var
vsval
- 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