Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSourabh Pal
210 PointsProperty
The property in Kotlin is always just getters and setters? Or the property means all functions in a class?
1 Answer
Ben Deitch
Treehouse TeacherIt's just the getters and setters. For example, here I'm creating a property named 'x':
var x: Int = 100
However, behind that code is literally this:
var x: Int = 100
get() {
return field
}
set(value) {
field = value
}
So when you create a property in Kotlin, typically it'll have a backing field named 'field'. You don't have to create this field; in fact you can't even really access it. But it's there, and it's used to store the value of the property.
Sourabh Pal
210 PointsSourabh Pal
210 PointsThank you for clearing that up Ben.