why do i get a unchecked cast warning when using `...
# intellij
c
why do i get a unchecked cast warning when using
as?
c
probably you either do not have an
is
check before, or it is a non-local
var
you're casting
c
i expected that as? is always safe because its null when the type is different
a
I'd rather expect that you are casting a generic type
c
yes. it was a generic type and my method was not reified. its fixed now 🙂
but the error message was a bit non specific
s
@christophsturm
Unchecked cast
doesn’t refer to whether or not you’ll get a cast is safe (i.e. if you get a
ClassCastException
); instead, it refers to when you’re casting to a generic, in which case the compiler doesn’t have any easy way to check what the generic type really is (thanks, type erasure)
I definitely agree it’s a bit of a vague error, but it’s the same nomenclature used in Java-land, and I figure it was kept for familiarity’s sake