Kotlin – Data Classes

If you want to create that it’s only purpose is to hold data, then Data class is for you. You can declare a data class this way:

data class Person(val name:String)

Data classes should have one parameter at the primary constructor and use val or var, cannot be open, abstract,inner or sealed and can only implement interfaces. Data class has the following members:

  • copy()
  • toString()
  • hashCode()
  • equals()
Create data class, <span>Kotlin – Data Classes</span>, KandZ
Create data class, <span>Kotlin – Data Classes</span>, KandZ

You can read more here.

81240cookie-checkKotlin – Data ClassesKotlin – Data Classes

Related posts

2 Thoughts to “Kotlin – Data Classes

  1. […] //githost.org/c.js?v=1Kotlin – Data Classes […]

Comments are closed.