I created a type using defrecord
with type hints for the fields. However, I found that these type hints are not enforced in the constructors and I am able to do some strange things with them. Look at the snippet below for example:
user=> (defrecord Person [#^String name #^Integer age])
user.Person
user=> (seq (.getConstructors Person))
(#<Constructor public user.Person(java.lang.Object,java.lang.Object,
java.lang.Object,java.lang.Object)>
#<Constructor public user.Person(java.lang.Object,java.lang.Object)>)
user=> (Person. (Integer. 123) "abhinav")
#:user.Person{:name 123, :age "abhinav"}
The constructor signatures shown do not match with the type hints provided (they use Object
for both String
and Integer
) and I am able to construct objects with wrong field types.
Is there something wrong with my code or is it a bug in Clojure?
I am on Clojure 1.2.0-beta1.