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

David Glasser

10/24/2019, 10:30 PM
does kotlin (jvm) have any kind of weak identity map, or an equivalent feature (ie, to let my code effectively add a property to an arbitrary object)? I know Java has WeakHashMap but I want the map to be based on identity, not hashCode.
d

darkmoon_uk

10/24/2019, 10:59 PM
@David GlasserI don't think so; I used Guava MapMaker on my JVM MP target and NSMapTable for iOS to achieve this kind of flexibility.
n

nfrankel

10/25/2019, 3:40 AM
if you want to add a property to a class you can use extension properties https://kotlinlang.org/docs/reference/extensions.html#extension-properties
d

David Glasser

10/25/2019, 3:41 AM
That can't actually store any data
n

nfrankel

10/25/2019, 3:42 AM
perhaps you could detail more what’s your requirement?
d

Derek Peirce

10/25/2019, 8:18 AM
WeakHashMap
is suggested to only be used on objects that already use identity for equivalence. Perhaps you should ensure that your intended keys use identity equality as well.
i

ikej

10/25/2019, 8:36 AM
You're probably looking for ephermerons, unfortunately they do not exist on the JVM https://en.wikipedia.org/wiki/Ephemeron
n

nfrankel

10/25/2019, 10:12 AM
i learned something thanks @ikej
👍 1
j

jpg

11/02/2019, 4:49 AM