ADocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
data object in Kotlin is a singleton declaration that instructs the compiler to automatically generate toString(), equals(), and hashCode() functions based on the object’s name and type. Introduced in Kotlin 1.9.0, it provides the structural symmetry of a data class while maintaining the single-instance guarantee of a standard object.
Compiler-Generated Functions
When you declare adata object, the Kotlin compiler synthesizes three specific member functions:
toString(): Returns the exact literal name of the object as aString.equals(other: Any?): Returnstrueif theotherreference is an instance of the exact samedata objecttype.hashCode(): Returns a consistent, pre-calculated integer hash specific to the singleton’s type, ensuring stable behavior in hash-based collections.
Behavioral Differences from Standard Objects
A standardobject relies on the default Any implementation for its string representation, which appends the object’s memory address hash. A data object overrides this to return its clean identifier.
Omitted Data Class Functions
Unlike adata class, a data object does not generate the following functions:
copy(): Omitted because singletons inherently forbid the creation of cloned or mutated instances. The type system enforces that only one instance of the object exists in the JVM.componentN(): Omitted because adata objectlacks a primary constructor and therefore has no properties to destructure.
Inheritance Rules
Adata object adheres to the exact same inheritance rules as a standard object. It can extend open or abstract classes and implement interfaces.
Equality Semantics
Because adata object is a singleton, referential equality (===) and structural equality (==) will always yield the same result when comparing it against itself. However, the generated equals() method ensures that if the data object is serialized and deserialized (or instantiated via reflection in edge cases), structural equality remains intact based on the type rather than the memory reference.
Master Kotlin with Deep Grasping Methodology!Learn More





