> I guess that if you enable reflection warnings, you'll get a warning on > the line where you invoke the constructor. > > I think the reflective dispatch doesn't pick the good constructor and > invokes OtpErlangBitstr(Object) instead of OtpErlangBitstr(byte[]). > Thus your byte[] is serialized and the 35 above is the length of the > serialized array. > > A type hint on s should fix the issue: > > (defmethod to-otp String [ #^String s ] > (OtpErlangBinary. (.getBytes s "utf-8")))
Ok, that worked, but I don't understand why. How does forcing the type of s to be String cause the dispatch to use the byte[] constructor instead of the Object constructor? This would make sense if we were somehow coercing the return value of .getBytes to be a byte[] instead of an Object, but I don't see how the type checker is calling any constructor other than a byte[] constructor when that's the return value of getBytes already. Does this have anything to do with the fact that (class (first (.getBytes "hi"))) gives java.lang.Byte instead of just plain byte? I had noticed that (and thus the subject of this topic), but in my smaller tests it didn't seem to matter. --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---