Objects
Kotlin Study Group
John
Hi, I am John
- Android Developer
- Work on Rakuten Viki
- Use Kotlin for 2 years
- Linkedin:
https://www.linkedin.com/in/chang-john-0a95237a/
Outline
- Preface
- Object
- Object declarations
- Object expressions
- Companion Objects
- Nested Classes
- Data Classes
- ADT(Algebraic Data Type)
- Enumerated Classes
- Sealed Classes
- Operator overloading
- destructure operator
Preface
- Understand usage scenario
- Know discrepancy of concept between Kotlin and Java
What’s meaning of object keyword?
If you need to hold on to a single instance with state that is consistent throughout the
time that your program is running, consider defining a singleton.
According different usages, there are three ways to use the object keyword:
- object declarations(singleton design pattern)
- object expressions(anonymous implementation)
- companion objects(instance/factory design pattern)
Object declarations
Object expressions
Object expression is replacement of anonymous class in Java
Object expression is inner class !!!
Companion objects - define
Companion objects - usage in Kotlin
Companion Object - usage in Java
Nested Class
Nested Class - tricky question
Nested Class is not equal to Inner Class
Data Class
data classes are classes designed specifically for holding data, and they
come with some powerful data manipulation benefits
- toString()
- equals()
- copy()
- destructuring
Data Class
Class without marked data
Data Class Rule
Enumerated Classes
What enum class is similar between Kotlin and Java?
What enum class are different between Kotlin and Java?
Enumerated Class - even override
Sealed class
Kotlin would checks ADT type Exhaustively
Operator Overloading
Destructure Operator

Objects