1.3.0 permalink Arrow_down_16x16



  • (bytes xs)
Casts to bytes[]

1 Example top

  • ;; for fast interop
    user=> (bytes (byte-array (map (comp byte int) "ascii")))
    #<byte[] [B@7a004f62>
    user=> (def the-bytes *1)
    user=> (defn get-byte [the-bytes i] (aget the-bytes i))
    #'user/get-byte Reflection warning, NO_SOURCE_PATH:1 - call to aget can't be resolved.
    user=> (defn get-byte [the-bytes i] 
             (let [the-bytes (bytes the-bytes)] 
               (aget the-bytes i)))
    user=> (get-byte the-bytes 0)
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:4670 top

(definline bytes
  "Casts to bytes[]"
  {:added "1.1"}
  [xs] `(. clojure.lang.Numbers bytes ~xs))
Vars in clojure.core/bytes:
Used in 0 other vars

Comments top

3 comment(s) for bytes.

Why is the (comp byte int) required in the example? This seems to work just as well:

user=> (def b (bytes (byte-array (map byte "ascii"))))
user=> (String. b)

For that matter, why is the bytes needed? Consider:

user=> (String. (byte-array (map byte "ascii")))

AFAIK, bytes is used for referring to bytes[].class from JAVA

Example (midje):

 (fact (class (.getBytes "test")) => bytes) ; true
Log in to add a comment.