https://kotlinlang.org logo
d

dmitry.petrov

08/14/2017, 9:01 AM
We have another solution on the table:
x
in
x as T
should be resolved with an expected type T. So, code like
findViewById(...) as MyView
would work as it did before.
r

Ruckus

08/14/2017, 2:01 PM
I don't entirely understand this. I assume this would only affect calls to generic functions. Would it convert
findViewById(...) as MyView
to
findViewById<MyView>(...)
, or would it just be some sort of compiler intrinsic (since the type is erased anyway)?
d

dmitry.petrov

08/14/2017, 6:34 PM
When you infer types for a generic call, there's an "expected type" for an expression that is taken into account as an additional constraint. So yes, it will affect inference for other expressions as well, although from our practice it's usually what people actually expect writing code like
foo() as Bar
.
r

Ruckus

08/14/2017, 7:22 PM
Ah, I see. For some reason I didn't realize you meant it would be part of type inference. Thanks for the explanation 🙂