scala-2.7

Converting a Java collection into a Scala collection

假如想象 提交于 2019-12-28 01:42:32
问题 Related to Stack Overflow question Scala equivalent of new HashSet(Collection) , how do I convert a Java collection ( java.util.List say) into a Scala collection List ? I am actually trying to convert a Java API call to Spring's SimpleJdbcTemplate , which returns a java.util.List<T> , into a Scala immutable HashSet . So for example: val l: java.util.List[String] = javaApi.query( ... ) val s: HashSet[String] = //make a set from l This seems to work. Criticism is welcome! import scala

Calling a method on the superclass in a self-typed trait in scala

不羁的心 提交于 2019-12-18 18:53:55
问题 I'm trying to create a trait that, when mixed in, will replace the default definition of a method with one that calls the original method and then manipulates the result. Here's what I'm trying to do: class Foo { def bar() : String = "Foos bar" } trait OtherStuff { self : Foo => def bar() : String = self.bar() + " with OtherStuff" } class Quux extends Foo with OtherStuff If this worked the way I wanted it to, then (new Quux).bar would now return Foos bar with OtherStuff . Unfortunately, it

Can I use for-comprehenion / yield to create a map in Scala?

試著忘記壹切 提交于 2019-12-08 23:39:26
问题 Can I "yield" into a Map? I've tried val rndTrans = for (s1 <- 0 to nStates; s2 <- 0 to nStates if rnd.nextDouble() < trans_probability) yield (s1 -> s2); (and with , instead of -> ) but I get the error TestCaseGenerator.scala:42: error: type mismatch; found : Seq.Projection[(Int, Int)] required: Map[State,State] new LTS(rndTrans, rndLabeling) I can see why, but I can't see how to solve this :-/ 回答1: scala> (for(i <- 0 to 10; j <- 0 to 10) yield (i -> j)) toMap res1: scala.collection

Strange behavior: Scala Actors 2.7.7 vs. 2.8-Snapshot

不打扰是莪最后的温柔 提交于 2019-12-05 12:35:40
I'm an 18 years old trainee and I'm discovering scala which I like very much :-). To get familiar with the scala actors I wrote a small simulation with some gears and one controller. The ActorApplication creates N gears with random speed. The controller calculates a synchronization speed and starts the gear-actors. The gears synchronize to this given speed step by step (1+ or 1-). The simulation is finished when all gears have reached the synchronization speed. I developed the simulation in scala 2.7.7 - and it worked as I expected it (see output below). However, when I swichted to the current

How to use Scala in IntelliJ IDEA (or: why is it so difficult to get a working IDE for Scala)?

╄→гoц情女王★ 提交于 2019-12-03 01:35:58
问题 I recently gave up trying to use Scala in Eclipse (basic stuff like completion doesn't work). So now I'm trying IntelliJ. I'm not getting very far. I've been able to edit programs (within syntax highlighting and completion... yay!). But I'm unable to run even the simplest "Hello World". This was the original error: Scala signature Predef has wrong version Expected 5.0 found: 4.1 in .... scala-library.jar But that was yesterday with IDEA 9.0.1. See below... UPDATE Today I uninstalled IntelliJ

Calling a method on the superclass in a self-typed trait in scala

折月煮酒 提交于 2019-11-30 17:07:04
I'm trying to create a trait that, when mixed in, will replace the default definition of a method with one that calls the original method and then manipulates the result. Here's what I'm trying to do: class Foo { def bar() : String = "Foos bar" } trait OtherStuff { self : Foo => def bar() : String = self.bar() + " with OtherStuff" } class Quux extends Foo with OtherStuff If this worked the way I wanted it to, then (new Quux).bar would now return Foos bar with OtherStuff . Unfortunately, it doesn't work that way - what I get is: <console>:6: error: error overriding method bar in class Foo of

Can I use for-comprehenion / yield to create a map in Scala?

一笑奈何 提交于 2019-11-30 11:21:49
Can I "yield" into a Map? I've tried val rndTrans = for (s1 <- 0 to nStates; s2 <- 0 to nStates if rnd.nextDouble() < trans_probability) yield (s1 -> s2); (and with , instead of -> ) but I get the error TestCaseGenerator.scala:42: error: type mismatch; found : Seq.Projection[(Int, Int)] required: Map[State,State] new LTS(rndTrans, rndLabeling) I can see why, but I can't see how to solve this :-/ scala> (for(i <- 0 to 10; j <- 0 to 10) yield (i -> j)) toMap res1: scala.collection.immutable.Map[Int,Int] = Map((0,10), (5,10), (10,10), (1,10), (6,10), (9,10), (2,10), (7,10), (3,10), (8,10), (4,10)