I have a feature proposal, want to hear some feedb...
# announcements
c
I have a feature proposal, want to hear some feedback before posting to YT: Let's say we have this interface:
fun <E : Entity, ID : Serializable> getRequired(id: ID): E
We can use it either like a)
getRequired<SomeEntity,Long>(1L)
or b)
val entity: SomeEntity = getRequired(1L),
It seems to me that case a) is unnecessarily verbose, I'd like to write
getRequired<SomeEntity>(1L)
, because
1L
already contains information about type of the second generic parameter, so compiler can infer it, like it does in case b).
i
c
thanks, I'll comment on that
k
there is always the possibility of an ugly workaround where you specify a useless second parameter that's just there to help type inference
Copy code
getRequired(1L, of<SomeEntity>())

fun <T: Any> of() = null as T?
b
The workaround can be useful if you specify second parameter as Class<E>
Copy code
getRequired(1L, SomeEntity::class.java
and inside check for instance