2

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?

1 Answer 1

10

Just put the <T> after the class name:

data class GenericResponse<T>(
  val success: Boolean,
  val message: String,
  val data: T
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.