Trixy
Trixy

Reputation: 321

Generic Data class in Kotlin

Create a generic data class which has one variable data Type

data class <T> GenericResponse(
  val success: Boolean,
  val message: String,
  val data: T
)

To use it: GenericResponse<SomeOtherDataClass>

How to do this in kotlin?

Upvotes: 2

Views: 2843

Answers (1)

Joffrey
Joffrey

Reputation: 37710

Just put the <T> after the class name:

data class GenericResponse<T>(
  val success: Boolean,
  val message: String,
  val data: T
)

Upvotes: 10

Related Questions