Skip to content

clojure.core/bytes

View this page on ClojureDocs

Type: function Added: Clojure 1.1 Examples: 2 Runnable: 0
([xs])

Casts to bytes[]

Examples

by leifp on . May have evaluation errors.
by tomdl89 on . May have evaluation errors.

Note by Brian Marick

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)
"ascii"

Note by Brian Marick

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

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

Note by xcthulhu

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

Example (midje):

 (fact (class (.getBytes "test")) => bytes) ; true

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.