https://kotlinlang.org logo
Title
k

Kroppeb

10/28/2019, 10:19 PM
If I have
sealed class Foo<T:Any> {
	object Bar : Foo<Nothing>()
	class Baz(val p: String) : Foo<String>()

	// I can do this
	fun String.convert() = this.let(::Baz)
}

// One type argument expected for class Foo<T : Any>
fun String.convert2() = this.let(Foo::Baz)

typealias FooBaz = Foo.Baz

fun String.convert3() = this.let(::FooBaz)
I get an error if i try
Foo::Baz
but adding a type makes
Baz
an unresolved reference. The code does work if all generics are removed. Can I fix this without import statements?
n

Nate

10/28/2019, 10:40 PM
Would this work?
fun String.convert2() = this.let{Foo.Baz(it)}
m

Marat Akhin

10/29/2019, 10:15 AM
You could try
Foo<*>::Baz
, and I believe it should work as expected