Ahh, thanks. I was wondering how to specify Collection 
<https://docs.oracle.com/javase/7/docs/api/java/util/Collection.html><? 
extends E 
<https://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html>>, but 
looks like just Collection will work.

On Tuesday, January 26, 2016 at 4:57:53 PM UTC-6, Beau Fabry wrote:
>
> Tell the compiler that the type you're passing to the constructor is a 
> Collection, so it will know which constructor to use without reflection.
>
> (set! *warn-on-reflection* true)
> => true
> (import '(java.util ArrayList Collection))
> => java.util.Collection
> (ArrayList. (list 1 2))
> Reflection warning, 
> /Users/bfabry/Library/Caches/IdeaIC15/tmp/form-init108635367050123227.clj:1:1 
> - call to java.util.ArrayList ctor can't be resolved.
> => [1 2]
> (ArrayList. ^Collection (list 1 2))
> => [1 2]
>
>
>
> On Tuesday, January 26, 2016 at 1:56:19 PM UTC-8, Ritchie Cai wrote:
>>
>> Quoting for small example like I mention is not an issue, but in general, 
>> I need to pass an vector or list, since that's what I get, in which case I 
>> cannot quote. 
>>
>> On Tuesday, January 26, 2016 at 3:52:17 PM UTC-6, Michael Willis wrote:
>>>
>>> What's not practical about quoting?  I thought it was considered more 
>>> idiomatic than doing (list ...)
>>>
>>> On Sunday, January 17, 2016 at 2:48:29 PM UTC-6, Ritchie Cai wrote:
>>>>
>>>> Hi all,
>>>>
>>>> I'm trying to create a Java ArrayList object from a Clojure collection 
>>>> to pass to another Java API. I get reflection warnings when the elements 
>>>> are not primitive types, in this case I'm using SparseIndexedVector 
>>>> class from vectorz library.
>>>>
>>>> (ArrayList. [c0 c1 c2])
>>>> Reflection warning, *cider-repl localhost*:77:11 - call to 
>>>> java.util.ArrayList ctor can't be resolved.
>>>>
>>>> where c0 c1 c2 are of type SparseIndexedVector. Alternatively, I can 
>>>> create create ArrayList then add elements one by one in a loop.
>>>>
>>>> (doto (ArrayList.)
>>>>    (.add c0)
>>>>    (.add c1)
>>>>    (.add c2))
>>>>
>>>> But I'm wondering if there is away to get rid of the the reflection 
>>>> warning when calling ArrayList constructor. 
>>>>
>>>> Also, quoting a list will not give reflection warning:
>>>>
>>>> (ArrayList. '(c0 c1 c2))  ;; no warning
>>>>
>>>> (ArrayList. (list c0 c1 c2)) 
>>>> Reflection warning, *cider-repl localhost*:77:11 - call to 
>>>> java.util.ArrayList ctor can't be resolved.
>>>>
>>>> However, quoting is not very practical.
>>>>
>>>> Thanks
>>>> Ritchie
>>>>
>>>>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to