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

**URL:** <https://discuss.kotlinlang.org/t/how-to-declare-a-class-that-contains-a-field-with-generic-type-in-kotlin/3942>\
**Category:** Uncategorized\
**Created:** [July 28, 2017, 11:24am UTC](https://discuss.kotlinlang.org/t/how-to-declare-a-class-that-contains-a-field-with-generic-type-in-kotlin/3942 "2017-07-28T11:24:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeroarst](https://avatars.discourse-cdn.com/v4/letter/z/b38774/32.png) [@zeroarst](https://discuss.kotlinlang.org/u/zeroarst)\
**Post date:** [July 28, 2017, 11:24am UTC](https://discuss.kotlinlang.org/t/how-to-declare-a-class-that-contains-a-field-with-generic-type-in-kotlin/3942/1 "2017-07-28T11:24:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![tieskedh](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/tieskedh/32/2816_2.png) [@tieskedh](https://discuss.kotlinlang.org/u/tieskedh)\
**Post date:** [July 28, 2017, 11:50am UTC](https://discuss.kotlinlang.org/t/how-to-declare-a-class-that-contains-a-field-with-generic-type-in-kotlin/3942/2 "2017-07-28T11:50:10Z")

</div>

```
class APIError(message: String, response: APIResponse<*>?) : Exception(message) {}

```

for info see: [https://kotlinlang.org/docs/reference/generics.html#star-projections](https://kotlinlang.org/docs/reference/generics.html#star-projections)

ps. When you know the Java-code and want the Kotlin-code, use your editor for it. in Windows -IntelliJ the shortcut is ctrl+shift+k
