How is one type to call an argument to a function call when the argument passed is a literal nil ? I came across a situation when I try to proxy a Java class with several constructors with one argument, for example:
public class MyClass { public MyClass(String a) {...} public MyClass(List b) {...} }
I want to call a constructor that takes a string argument for my proxy, but passes it a null value for this argument. Just by calling:
(proxy [MyClass] [nil] ...)
throws an exception because Clojure finds several constructors and does not know which one to call. But when trying to add a type hint, for example:
(proxy [MyClass] [^String nil] ...)
throws an exception with the message "Metadata can only be applied to IMetas." Fair enough - when reading the nil literal, nothing is needed to read the metadata. So how can I get around this? I was able to come up with a solution that included let , but it seems to be kludgy:
(let [NIL! nil] (proxy [MyClass] [^String NIL!] ...))
Is there a better way to do this?
source share