how can i compare two method references to see if ...
# announcements
t
how can i compare two method references to see if they are equivalent ? in java serializing them appears to work, but in kotlin they serialize to different bytearrays
a
@tipsy*point to the same instance-method/function* or are the same reference?
t
well, either would work.. but method references create an implementation when they're called (?), so there is nothing really to compare? 🤔
k
==
doesn't work?
t
@karelpeeters no
should it?
k
I don't know, it's not really clear what you're asking. Can you give some example code?
i have a map where i register things that fulfill an interface, that can be classes that implement the interface, typed lambda fields of the interface, or method references.
Copy code
map.put("someString", fieldLambda)
map.put("someString", implementingClass)
map.put("someString", ::methodReference)
i want to be able to get the key based on a value
k
Copy code
fun foo() {}
println(::foo == ::foo)
prints true for me.
Do you want to see if the code contained in method references and in lambdas equal each other?
t
ideally not, but that's what i had to resort to for java method references at least. that code prints true for me too, i need to find out why it doesn't in my other function 🤔
a
@tipsy if its an instance-method, both need to point to the same instance
t
i think some info is lost since it passes through a java method which changes it from a kfunction to an implementation of the interface
these things make my head hurt though, so i put it aside for the night, thanks for your help