java

Ben Sless 2023-06-30T09:58:40.245339Z

How can I pass a static method as an argument?

jkxyz 2023-06-30T10:14:05.069439Z

If you mean as an argument to a Clojure function, wrap it in a function like #(UUID/randomUUID)

Ben Sless 2023-06-30T10:15:46.588779Z

As an argument to a java static method 🙂

jkxyz 2023-06-30T10:19:05.065199Z

I would hesitantly suggest using a lambda expression, but I've not used them in Java 😄

Ben Sless 2023-06-30T10:26:13.297359Z

That seems right

Alex Miller (Clojure team) 2023-06-30T11:58:06.952479Z

In Java or in Clojure?

Alex Miller (Clojure team) 2023-06-30T11:58:30.550729Z

In Java, as a Class::method method reference

Alex Miller (Clojure team) 2023-06-30T11:59:33.845499Z

From Clojure right now, you’ll need to reify a Java functional interface (but this is an area of active work)

Ben Sless 2023-06-30T12:50:31.565199Z

This is a pure java question What's the type of that argument? How do I invoke the method I passed as an argument?

Alex Miller (Clojure team) 2023-06-30T13:17:01.497689Z

it depends on the method

Alex Miller (Clojure team) 2023-06-30T13:19:21.160929Z

it's being treated as some kind of functional interface, so a method that is Object f(Object) could be typed as a java.util.function.Function for example

Ben Sless 2023-06-30T13:32:40.538849Z

clojure.lang.Util/equiv and clojure.lang.Util/equals 🙂

Ben Sless 2023-06-30T13:42:09.462639Z

BiPredicate?

Alex Miller (Clojure team) 2023-06-30T13:53:43.448149Z

what are you passing it to?

Alex Miller (Clojure team) 2023-06-30T13:54:44.919149Z

BiPredicate is probably the best match there

Ben Sless 2023-06-30T14:00:56.258419Z

I have a couple of static methods whose only difference is which static method they're calling, equiv/equals

emccue 2023-06-30T17:14:01.937489Z

You can make your own interface

emccue 2023-06-30T17:17:01.839529Z

interface EqualityMethod {
    static EqualityMethod EQUIV = clojure.lang.Util::equiv;
    static EqualityMethod EQUALS = clojure.lang.Util::equals;
    boolean areEquivalent(Object a, Object b);
}