Re: Strange problem with Scala 2.10
Jon Pretty <[email protected]>
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <CAE45xcjVC0dEGsmy2VwgdLJZ==-8fxu3emw23U0ikjTo_+z2rw@mail.gmail.com> |
Hi Oliver, I think the heuristic is that the REPL puts quotes around strings if they start or end with whitespace. Cheers, Jon On Fri, 27 Feb 2015 at 02:31 Oliver Ruebenacker <[email protected]> wrote: > > Hello, > > Normally, REPL does not put quotations around Strings, or does it? So > the quotation marks are part of the Strings, then, right? Try: > > > c.asInstanceOf[Map[String, Any]].apply("\"features\"") > > If it's not that, I would try println(c.getClass) and println(c). > > And: > > val map = c.asInstanceOf[Map[String, Any]] > map(map.keys.head) > > Best, Oliver > > > > On Thu, Feb 26, 2015 at 6:54 PM, Jiakui Wang <[email protected]> wrote: > >> I got the variable c from previous code, and it behaves very strangely: >> >> scala> c.asInstanceOf[Map[String, Any]].keys >> res24: Iterable[String] = *Set("label", "features")* >> >> scala> c.asInstanceOf[Map[String, Any]].apply("features") >> *java.util.NoSuchElementException: key not found: features* >> at scala.collection.MapLike$class.default(MapLike.scala:228) >> at scala.collection.AbstractMap.default(Map.scala:58) >> at scala.collection.MapLike$class.apply(MapLike.scala:141) >> at scala.collection.AbstractMap.apply(Map.scala:58) >> at .<init>(<console>:14) >> at .<clinit>(<console>) >> at .<init>(<console>:7) >> at .<clinit>(<console>) >> at $print(<console>) >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> at >> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) >> at >> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) >> at java.lang.reflect.Method.invoke(Method.java:483) >> at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:734) >> at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:983) >> at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:573) >> at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:604) >> at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:568) >> at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:760) >> at >> scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:805) >> at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:717) >> at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:581) >> at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:588) >> at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:591) >> at >> scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:882) >> at >> scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:837) >> at >> scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:837) >> at >> scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135) >> at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:837) >> at scala.tools.nsc.interpreter.ILoop.main(ILoop.scala:904) >> at xsbt.ConsoleInterface.run(ConsoleInterface.scala:69) >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> at >> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) >> at >> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) >> at java.lang.reflect.Method.invoke(Method.java:483) >> at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:102) >> at sbt.compiler.AnalyzingCompiler.console(AnalyzingCompiler.scala:77) >> at sbt.Console.sbt$Console$$console0$1(Console.scala:23) >> at >> sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply$mcV$sp(Console.scala:24) >> at sbt.TrapExit$.sbt$TrapExit$$executeMain$1(TrapExit.scala:33) >> at sbt.TrapExit$$anon$1.run(TrapExit.scala:42) >> >> >> Any idea about the problem? >> >> Thanks >> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "scala-language" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Oliver Ruebenacker > Solutions Architect at Altisource Labs <http://www.altisourcelabs.com/> > Be always grateful, but never satisfied. > > -- > You received this message because you are subscribed to the Google Groups > "scala-language" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "scala-language" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.