Home > Net >  Generic Data class in Kotlin
Generic Data class in Kotlin

Time:03-05

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?

CodePudding user response:

Just put the <T> after the class name:

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