Yes, they both work - and the "#^chars" is much more legible.

Many thanks!

FYI, to whom it may concern...I think it's worth noting that this
simple
case gives confusing output from the repl.

     user=> (new String #^chars (make-array Character/TYPE 3))
     "user=>

And this:

    user=> (def asdf (new String #^chars (make-array Character/TYPE
3)))
    #'user/asdf
    user=> asdf
    "

That's the exact output except for the indentation.  The dangling
string
w/ its single double-quote followed by the prompt.  The prompt is not
even displayed w/ the second example.

As you can see from this example, non-empty strings are displayed
as expected.

    user=> (def qwer (let [x (make-array Character/TYPE 3 )] (aset x 0
\a) (aset x 1 \b) (aset x 2 \c) (new String #^chars x)))
    #'user/qwer
    user=> qwer
    "abc"

CHICKEE

On Oct 28, 10:31 pm, ataggart <alex.tagg...@gmail.com> wrote:
> Also you can substitute #^"[C" with the more legible #^chars.
>
> On Oct 28, 7:27 pm, Alex Osborne <a...@meshy.org> wrote:
>
> > Chick Corea wrote:
> > > What is wrong with this code?  I want to instantiate a Java String
> > > from a Java character-array.
> > > But I want it to be fast, hence the need to cast per the "warn on
> > > reflection" message.
>
> > >     user=> (set! *warn-on-reflection* true)
> > >     true
> > >     user=>  (new String #^"[C" (make-array Character/TYPE 3 \a ))
> > >     java.lang.ClassCastException: [[C cannot be cast to [C
> > > (NO_SOURCE_FILE:0)
>
> > Note the exception, "[[C" means a two-dimensional arary.  (make-array
> > Character/TYPE 3 \a) actually means (make-array Character/TYPE 3 97) so
> > a 3 by 97 two-dimensional array (new char[3][97] in java syntax).  What
> > you probably want is:
>
> > user> (String. #^"[C" (into-array Character/TYPE (repeat 3 \a)))
> > "aaa"

--~--~---------~--~----~------------~-------~--~----~
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
Note that posts from new members are moderated - please be patient with your 
first post.
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to