In Kotlin both the header and the body are optional; if the class has no body, curly braces can be omitted.
So we can define class like,
class Empty
What is the use of this type of class?
In Kotlin both the header and the body are optional; if the class has no body, curly braces can be omitted.
So we can define class like,
class Empty
What is the use of this type of class?
You can use it for some custom exceptions:
class Empty : Exception()
or as a marker interface:
interface Empty
or as a data class:
data class Empty(val s: String)
or as a marker annotation:
annotation class Empty
~ That's a good post to read.
Kotlin allows to declare any type without body, for example:
interface Interface;
class Class;
annotation class Annotation;
sealed class SealedClass;
data class DataClass(var value: String);
object ObjectClass;
enum class EnumClass;
class CompanionClass {
companion object
}
the usage of each definition can be described as below:
@Before
and @After
annotations.synchronized(lock){ /*thread safe working*/ }
getters
, setters
? , equals
, hashCode
, toString
and componentN
operators for destructuring in kotlin.