Welcome! Please see the About page for a little more info on how this works.

+3 votes
in Java Interop by

I am trying to use a Java library that uses annotations on Java classes and methods, so I pass to it deftypes with annotated methods. Some of the annotations require using integer parameters and it seems there is no convenient way to do this in Clojure. The code I am trying is something like this:

(deftype SomeType []
  (^{Retention RetentionPolicy/RUNTIME
     SomeAnnotationClass {:order 1} }
   someMethod [_]...)) 

The :order 1 part causes an exception:

Incorrectly typed data found for annotation element ... (Found data of type java.lang.Long[1])

This happens because the java library expects that :order would have a java.lang.Integer value, but Clojure creates a java.lang.Long. If I try (int 1) instead of 1, I get another exception.

I asked for help on clojurians Slack, and it was suggested that I use #java.lang.Integer[1] instead of simply 1. This works, but it would be nice to have a more intuitive way to do this.

1 Answer

0 votes
by
...