what is the correct syntax for specifying multiple generic bounds/constraints in Kotlin?
class CustomClass<T> where T: Constraint1, T: Constraint2,
ParentClass<T>(), Interface1 { /* ... */ }
here Constraint1 and Constraint2 are unrelated constraints/bounds on T (eg: disjoint interfaces that T implements) and ParentClass is a generic (base) class also. Interface1 is an interface CustomClass will satisfy
You need to specify the base class and the interfaces before the where clause:
class CustomClass<T>
: ParentClass<T>(), Interface1
where T : Constraint1, T : Constraint2 {
/* ... */
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With