https://kotlinlang.org logo
#language-proposals
Title
# language-proposals
m

mplatvoet

05/21/2016, 7:09 AM
@mikehearn, @kirillrakhman: FWIW, there are plenty of alternatives when using a factory instead:
Copy code
fun main(args: Array<String>) {
    SomeType() { "" }
    
    SomeType<String>()
    
    SomeType(::String)
}

class SomeType<T: Any>(factory : () -> T) {
    val instance = factory()
    
    companion object {
        inline operator fun <reified T: Any> invoke() = SomeType() {
            T::class.java.newInstance()
        }
    }
}