scala-2.10

Scala 2.10 + Json serialization and deserialization

99封情书 提交于 2019-11-27 00:10:40
问题 Scala 2.10 seems to have broken some of the old libraries (at least for the time being) like Jerkson and lift-json. The target usability is as follows: case class Person(name: String, height: String, attributes: Map[String, String], friends: List[String]) //to serialize val person = Person("Name", ....) val json = serialize(person) //to deserialize val sameperson = deserialize[Person](json) But I'm having trouble finding good existing ways of generating and deserializing Json that work with

IntelliJ IDEA Report Highlighting error when using routes in Controller

情到浓时终转凉″ 提交于 2019-11-26 23:58:16
问题 I have a Scala Play project. I'm using Play 2.2.1. I downloaded Scala, Play 2 supported and SBT plugins. Everything is OK, but When I call route on Action in the Controller appear following error(Look screenshots): I'm using IntelliJ IDEA 12.1.6 Ultimate version. Scala version 2.10.2 Anybody know how to fix this problem? Thanks in advance! Edit When I generate my project to Intellij IDEA via "play idea" command in play console, and I opened project in IDEA project structure was such: Then I

How do I access default parameter values via Scala reflection?

南楼画角 提交于 2019-11-26 20:18:16
问题 Let's say a I have a class: case class Foo(id: Int, name: String, note: Option[String] = None) Both the constructor and the apply method in the automatically generated companion object take three parameters. When viewed via reflection, the third parameter (note) is flagged: p.isParamWithDefault = true Also, by inspection I can find the method that produces the value in the companion object: method <init>$default$3 and method apply$default$3 Which both also have: m.isParamWithDefault = true

Static return type of Scala macros

断了今生、忘了曾经 提交于 2019-11-26 17:37:31
问题 So I've got this macro: import language.experimental.macros import scala.reflect.macros.Context class Foo class Bar extends Foo { def launchMissiles = "launching" } object FooExample { def foo: Foo = macro foo_impl def foo_impl(c: Context): c.Expr[Foo] = c.Expr[Foo](c.universe.reify(new Bar).tree) } I've said three times that I want foo to return a Foo , and yet I can do the following (in 2.10.0-RC3): scala> FooExample.foo res0: Bar = Bar@4118f8dd scala> res0.launchMissiles res1: String =

Scala's “postfix ops”

徘徊边缘 提交于 2019-11-26 17:25:48
I've searched for a half-hour, and still cannot figure it out. In SIP: Modularizing Language Features there are a number of features which will require explicit "enabling" in Scala 2.10 ( import language.feature ). Amongst them there is postfixOps , to which I just cannot find a reference anywhere. What exactly does this feature allow? It allows you to use operator syntax in postfix position. For example List(1,2,3) tail rather than List(1,2,3).tail In this harmless example it is not a problem, but it can lead to ambiguities. This will not compile: val appender:List[Int] => List[Int] = List(1

Generating a class from string and instantiating it in Scala 2.10

◇◆丶佛笑我妖孽 提交于 2019-11-26 17:10:15
In Scala 2.10 how do I generate a class from string (probably, using the Toolbox api) later to be instantiated with Scala's reflection? W.r.t compilation toolboxes can only run expressions = return values, but not resulting classes or files/byte arrays with compilation results. However it's still possible to achieve what you want, since in Scala it's so easy to go from type level to value level using implicit values: Edit . In 2.10.0-RC1 some methods of ToolBox have been renamed. parseExpr is now just parse , and runExpr is now called eval . scala> import scala.reflect.runtime._ // requires

String interpolation in Scala 2.10 - How to interpolate a String variable?

隐身守侯 提交于 2019-11-26 16:04:37
问题 String interpolation is available in Scala starting Scala 2.10 This is the basic example val name = "World" //> name : String = World val message = s"Hello $name" //> message : String = Hello World I was wondering if there is a way to do dynamic interpolation, e.g. the following (doesn't compile, just for illustration purposes) val name = "World" //> name : String = World val template = "Hello $name" //> template : String = Hello $name //just for illustration: val message = s(template) //>

Use case of scala.concurrent.blocking

北战南征 提交于 2019-11-26 10:21:28
问题 I came across the scala.concurrent.blocking method, and according to the Scala documentation this is... Used to designate a piece of code which potentially blocks, allowing the current BlockContext to adjust the runtime\'s behavior. Properly marking blocking code may improve performance or avoid deadlocks. I have some doubts: what is the factor with which new threads will be spawned? Is this applicable only for scala.concurrent.ExecutionContext.Implicits.global execution context or for user

Scala&#39;s “postfix ops”

北慕城南 提交于 2019-11-26 05:26:48
问题 I\'ve searched for a half-hour, and still cannot figure it out. In SIP: Modularizing Language Features there are a number of features which will require explicit \"enabling\" in Scala 2.10 ( import language.feature ). Amongst them there is postfixOps , to which I just cannot find a reference anywhere. What exactly does this feature allow? 回答1: It allows you to use operator syntax in postfix position. For example List(1,2,3) tail rather than List(1,2,3).tail In this harmless example it is not

Scala: What is a TypeTag and how do I use it?

 ̄綄美尐妖づ 提交于 2019-11-25 23:17:24
问题 All I know about TypeTags is that they somehow replaced Manifests. Information on the Internet is scarce and doesn\'t provide me with a good sense of the subject. So I\'d be happy if someone shared a link to some useful materials on TypeTags including examples and popular use-cases. Detailed answers and explanations are also welcome. 回答1: A TypeTag solves the problem that Scala's types are erased at runtime (type erasure). If we wanna do class Foo class Bar extends Foo def meth[A](xs: List[A]