Fork me on GitHub
#java
<
2020-09-23
>
mheld20:09:36

is there some sort of extra hinting I have to do to handle reifying a Consumer of a generic type?

mheld20:09:52

I keep on getting class cast errors

mheld20:09:54

Syntax error (ClassCastException) compiling at (/tmp/form-init17042598140599140008.clj:1:74). class aishub.core$consumer$reify__166 cannot be cast to class [Ljava.util.function.Consumer; (aishub.core$consumer$ reify__166 is in unnamed module of loader clojure.lang.DynamicClassLoader @29f0802c; [Ljava.util.function.Consumer; is in module java.base of loader 'bootstrap')

mheld20:09:37

(defn ^Consumer consumer [] (reify Consumer (accept [this t] (println t))))

mheld20:09:44

with something calling (NMEAMessageHandler. "LS" (consumer) later

Alex Miller (Clojure team)20:09:11

you'll want the type hint before the [], not after defn

mheld20:09:59

that's a good catch! but I'm still getting the same error

mheld20:09:11

maybe a better practice to do a gen-class w/ :implements?

Alex Miller (Clojure team)22:09:43

shouldn't matter unless there's more to it than what you've shown

hiredman00:09:52

The method takes an array of consumers,not a single consumer

hiredman01:09:16

Likely java varargs