https://kotlinlang.org logo
#announcements
Title
# announcements
u

ursus

12/03/2019, 5:01 AM
Has anyone clue why my list reference doesnt update when used as method reference
s

Shawn

12/03/2019, 5:16 AM
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

ursus

12/03/2019, 5:21 AM
isnt that a bug?
s

Shawn

12/03/2019, 5:21 AM
no
well, it’s a bug in your program
they are semantically two different things
u

ursus

12/03/2019, 5:22 AM
in theory isnt method reference just sugar for the lambda?
s

Shawn

12/03/2019, 5:22 AM
Not at all.
u

ursus

12/03/2019, 5:23 AM
alright then there's the problem
2
s

Shawn

12/03/2019, 5:23 AM
An instance method reference is literally a reference to a method on a specified object
👍 1
1
2 Views