Why does the below code compile?
Inside SomeScope.getEntity()
:
get<Entity>()
clearly violates the bounds of the get()
function.
But if you omit <Entity>
(which you can because of return type inference) the code compiles.
interface EntityBase
interface Entity
class SomeScope {
inline fun <reified T : EntityBase> get(): T {
return "whatever" as T // doesn't matter
}
}
fun SomeScope.getEntity(): Entity {
return get() // get<Entity>() wouldn't compile
}