where are you seeing that?
# getting-started
s
where are you seeing that?
v
Here...
final
i.e. read-only?
s
final var
is weird, but yeah, probably
there should be a more specific error message for when you try to assign to a final field
I’d imagine this is an odd friction point in Java interop that leads to
Nothing!
being inferred for
T
in that instance
you may also wanna check out #tornadofx
v
Sure, but I was not sure that, it's TFX-specific
Ah, just revealed -- that
item
is a delegate:
var item by itemProperty
That delegate makes the variable
final
, right?
s
I haven’t actually done much at all with delegates, so I couldn’t tell you for sure
final
used in most instances in Kotlin doesn’t do a whole lot
the IDE just grays it out as redundant
v
Is it for compatibility with Java?
k
https://kotlinlang.org/docs/reference/classes.html#overriding-methods:
A member marked
override
is itself open, i.e. it may be overridden in subclasses. If you want to prohibit re-overriding, use `final`:
s
ahh, there it is
v
I did not pay attention, when was reading about overriding
k
It's easy to miss those small paragraphs sprinkled everywhere simple smile
i
ItemViewModel<*>
is an out-projected
ItemViewModel<T>
type. You cannot use its members where T is in
in
-position, such as the setter of
item
property.
v
Just was going to ask: what does mean
Setter for 'itemProperty' is removed by type projection
? 🙂
Is it possible to avoid this projection if a parameter type is not known or may vary?
i
If you know the type parameter you can cast that view model as
ItemViewModel<KnownType>
, otherwise you can cast it as
ItemViewModel<Any?>
(or its generic upper bound instead of
Any?
) and hope that the actual view model supports the item you're going to set. These casts are unchecked and inherently unsafe.
v
Compiler complains, when it sees
ItemViewModel<T>
instead of
ItemViewModel<Any?>
for a function's argument
Ok, casted
as ItemViewModel<Any>
And
item
became assignable
Thanks for the clue