How to declare a class that contains a field with generic type in Kotlin?

Viewed 1062

In Kotlin I have a data class.

data class APIResponse<out T>(val status: String, val code: Int, val message: String, val data: T?)

I want to declare another class to include this:

class APIError(message: String, response: APIResponse) : Exception(message) {}

but Kotlin is giving error: One type argument expected for class APIResponse defined in com.mypackagename

In Java I can do this:

class APIError extends Exception {

    APIResponse response;

    public APIError(String message, APIResponse response) {
        super(message);
        this.response = response;
    }
}

How can I convert the code to Kotlin?

1 Answers
Related