does kotlin (jvm) have any kind of weak identity m...
# announcements
d
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
@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
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
That can't actually store any data
n
perhaps you could detail more what’s your requirement?
d
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
You're probably looking for ephermerons, unfortunately they do not exist on the JVM https://en.wikipedia.org/wiki/Ephemeron
n
i learned something thanks @ikej
đź‘Ť 1
j