Creating an instance of a generic class

Report a typo

You have a generic class named MyClass.

class MyClass<T>(t: T) {

    val item = t  // A field of "some type"

}

Create an instance of MyClass with type the String. The value of the item should be equal to "hyperskill".

There is no need to declare a variable, just specify a class name with the desired parameters.

Enter a short text
___

Create a free account to access the full topic