"Can't embed object in code" error for UTF-8 constant in Clojure

Viewed 625

I want to keep a constant around to represent the UTF-8 Charset.

(java.nio.charset.Charset/forName "UTF-8")
; #<UTF_8 UTF-8>
(def ^:const utf-8 (java.nio.charset.Charset/forName "UTF-8"))
; #'user/utf-8
utf-8
; #<UTF_8 UTF-8>

But when I use it, I get an error:

(type utf-8)
; CompilerException java.lang.RuntimeException: Can't embed object in code, maybe print-dup not defined: UTF-8, compiling:(NO_SOURCE_PATH:1:1)

How can I fix this?

1 Answers
Related