Has anyone clue why my list reference doesnt updat...
# announcements
u
Has anyone clue why my list reference doesnt update when used as method reference
s
at class initialization time, you’re creating a reference to, for example,
ArrayList@3cbbc1e0#get
then using
setData
, you’re replacing that list
💯 1
call it
ArrayList@35fb3008
you’ve updated
items
, but
itemGetter
is still the same method reference to
get
on that first ArrayList
the reason the lambda works is because it’s a closure that (effectively) calls
this.getItems().get()
which prevents you from keeping a stale reference to an old, replaced, list
u
isnt that a bug?
s
no
well, it’s a bug in your program
they are semantically two different things
u
in theory isnt method reference just sugar for the lambda?
s
Not at all.
u
alright then there's the problem
2
s
An instance method reference is literally a reference to a method on a specified object
👍 1
1