Reputation: 106391
How do I remove the reflection warning from this Clojure code that is attempting to call a Java clone method:
(defn clone-foo [m]
(.clone m))
=> Reflection warning, NO_SOURCE_PATH:2 - reference to field clone can't be resolved.
Surely if m is any instance of java.lang.Object
it must have the clone
method?
Is it something to do with clone
being protected?
Upvotes: 0
Views: 124
Reputation: 53694
Yes, you can't call the clone()
on an arbitrary Object
. And, since the clone()
method is not exposed by Cloneable
, cloning things in a "generic" fashion is somewhat difficult. This is one of those leftover bits from the early days of java which is too late to change at this point. If you control all the objects you need to clone, you could create your own ReallyCloneable
interface which exposes the clone()
method, or you could play your own tricks with reflection.
Upvotes: 2