https://kotlinlang.org logo
#getting-started
Title
# getting-started
a

anlex N

03/24/2024, 7:57 AM
https://kotlinlang.org/docs/object-declarations.html 1. is
x
not data property? 2. what is data property? I can not find difinition in Properties
h

hfhbd

03/24/2024, 8:33 AM
I find the name "data property" confusing too, it’s not used anywhere else, but it stands for the properties defined in the (primary) constructor of a data class:
Copy code
data class Foo(val b: Int) {
val s: String = ""
}
b
is a "data property", while s is a normal property.
a

anlex N

03/24/2024, 8:43 AM
so crazy and confused. can we invite JetBrain team to answer this question?
c

CLOVIS

03/24/2024, 11:13 AM
There's nothing more to say, what Philip said is correct. A data property is just a property that's in the primary constructor of a data class.
j

Jacob

03/24/2024, 12:38 PM
https://kotlinlang.org/docs/data-classes.html#properties-declared-in-the-class-body describes the significance of properties declared in constructor
k

Klitos Kyriacou

03/25/2024, 10:26 AM
It seems to be true that the term "data properties" is not defined properly before use on that page. However, it is defined formally in the Kotlin Language Specification:
A data class is a special kind of class, which represents a product type constructed from a number of data properties, [...], described in its primary constructor.
It may be worth asking someone from JetBrains if they would make the tutorial page on data classes clearer with respect to this definition.
g

gildor

03/26/2024, 7:19 AM
There is a literally "Edit page" button on top of the page to send PR