clojure - Type hinting not enforced in defrecord constructors -
I have created a type using the defrecord
with type signals for the field, however Found that these types of signals are not implemented in constructors and I am capable of doing some strange things with them. For example, see Snippet below:
User = & gt; (Defrecord person [# # string name # ^ integer age]) user. User user = & gt; (Seq (.getConstructors person)) (# & lt; Constructor public user.Parson (java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object) & gt; # & lt; Constructor public user .Person (java.lang.Object, java.lang.Object) & gt;) User = & gt; (Individual (integer 123) "Innovation") #: user.Person {: 123 Name: Age "Innovation"}
The manufacturers shown are not provided with signature type signals ( They use both string
and integer
for objects
) and I am able to create an object with incorrect field types.
Is there anything wrong with my code or is it a bug in the closure?
I am on Closer 1.2.0-Beta 1.
Typ-hint is used to avoid reflection; They (currently) are not used to statically function or constructor args (since the exception can not be included under the object
), for a simple record Do not do much, but when it comes to adding protocol implementation, they do this:
user => (set * warning-on-reflection * true) True user => (Defproto Scroll P (Fu [p])) P user => (Defrekard R [S] P (Fu [_] (. Batret S))); There is a way to getBytes string reflection warning, NO_SOURCE_PATH: 6 - reference of field getBytes can not be resolved. User.r user => (foo (R5)) java.lang.IllegalArgumentException: no matching field found: getBytes for class java.lang.Integer (NO_SOURCE_FILE: 0) user => (defrecord R [^ String S] P (Foo [_] (.getBytes s)) user.r user => (foo (r5)) java.lang.ClassCastException: java.lang.Integer to java.lang.String (NO_SOURCE_FILE: 0)
The difference between the two versions is that the latter bytecode calling String.getBytecode ()
(hence the class class expansion when an integer was passed) Emits, while floods What is needed is actually the value of .getBytes
in relation to the runtime object in the function (and this process fails when the integer passes).
Comments
Post a Comment