On Oct 3, 9:17 am, Jung Ko <[email protected]> wrote:
> Is it possible to add meta-data to Strings?
>
> (with-meta "Hello" {:key 123})
>
> java.lang.String cannot be cast to clojure.lang.IObj
> [Thrown class java.lang.ClassCastException]
And String is final, making deriving from it impossible.
One way (most probably not the best way) would be to wrap it in a Var
and attach the metadata to the Var, i.e.
(def #^{:blah :foo} my-string "some string")
Note that to access the metadata of the Var later, you have to use var-
quote:
^#'my-string
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---