I'd like to use generics in companion object in this way:
class Foo<T> {
/* ... */
companion object {
fun foo(args: List<T>) {
/* ... */
}
}
}
Unfortunately the code above raise Unresolved reference: T
error.
You either need to declare the generic like so
fun <T> foo(args: List<T>) { ... }
or, if you don't care about the type, you can use a star projection
fun foo(args: List<*>) { ... }
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