This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Re: String.toCharArray behaving weirdly

No replies
jibal
Joined: 2010-12-01,
User offline. Last seen 1 year 45 weeks ago.

That doesn't address the question. res0 is a java.lang.String. It
prints in the REPL as "O$", but that's not its value; it's value is
actually "line0$object$$iw$$iw$O$" -- this can be confirmed by noting
that res0.length returns 23, res0(0) returns 'l', etc., or just by
printing it:

scala> println(res0)
line0$object$$iw$$iw$O$

And it's the value itself that gets this treatment; e.g.,

scala> val x = "line0$object$$iw$$iw$O$"
x: java.lang.String = O$

OTOH,

scala> val x = "ine0$object$$iw$$iw$O$"
x: java.lang.String = ine0$object$O$

That's pretty weird -- perhaps the REPL magician can explain this magic.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland