Search code examples
kotlinkotlin-generics

Kotlin class with generics and implementing interfcae


I'm using Kotlin in Android development and I would like to create class with two generics, one of them V must be child class of View, and class also should implement some interface MyInterface.

How to do that? I've tried something like this

class Test<T, V>(val value1: String, val map: Map<T, V>) where V: View, MyInterface

or

class Test<T, V>(val value1: String, val map: Map<T, V>) where V: View: MyInterface

but I have no idea what is the correct syntax?


Solution

  • class Test<T, V: View> (val string: String, val map: Map<T, V>) : MyInterface

    Should be the correct syntax.