0

Clojure empty changes types of Java collections. For example a JavaParser MethodCallExpr object mce,

(type (.getArguments mce))
;; => com.github.javaparser.ast.NodeList
(type (emtpy (.getArguments mce)))
;; => nil
(type (into (empty (.getArguments mce)) (.getArguments mce)))
;; => clojure.lang.PersistentList

But (.setArguments mce ???) needs ??? to be a NodeList<Expression>, so how to make an object ??? in clojure?

Thanks!

1 Answer 1

5

empty works only for classes that implement clojure.lang.IPersistentCollection. It won't work for anything else.

In your case, if you know that the type is NodeList, just construct it yourself via Java interop. If you don't know that it's NodeList in some general case, you're out of luck because you can't construct an instance of an arbitrary class based on a single assumption that it's a collection class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.