scala-2.8

Methods in trait become volatile methods when mixed in concrete classes in 2.9.0-1 but not 2.8.1

梦想与她 提交于 2019-12-07 09:18:10
问题 I noticed this breaking (for me using it with OGNL) change in 2.9.0-1: I find that, in 2.9, methods declared in a trait become volatile when mixed in a class: Example in 2.9.0-1 import java.lang.reflect.Modifier trait SuperTrait { def getKnoll = "Kanutten" } class KlassWithKnoll extends SuperTrait { def getKnall = "Mars" } val qsc = classOf[KlassWithKnoll] val knollGetter = qsc.getDeclaredMethod("getKnoll") println("isVolatile: " + Modifier.isVolatile(knollGetter.getModifiers())) This prints

Scala, make my loop more functional

你离开我真会死。 提交于 2019-12-07 04:10:38
问题 I'm trying to reduce the extent to which I write Scala (2.8) like Java. Here's a simplification of a problem I came across. Can you suggest improvements on my solutions that are "more functional"? Transform the map val inputMap = mutable.LinkedHashMap(1->'a',2->'a',3->'b',4->'z',5->'c') by discarding any entries with value 'z' and indexing the characters as they are encountered First try var outputMap = new mutable.HashMap[Char,Int]() var counter = 0 for(kvp <- inputMap){ val character = kvp.

Scala program exiting before the execution and completion of all Scala Actor messages being sent. How to stop this?

萝らか妹 提交于 2019-12-06 16:32:12
I am sending my Scala Actor its messages from a for loop. The scala actor is receiving the messages and getting to the job of processing them. The actors are processing cpu and disk intensive tasks such as unzipping and storing files. I deduced that the Actor part is working fine by putting in a delay Thread.sleep(200) in my message passing code in the for loop. for ( val e <- entries ) { MyActor ! new MyJob(e) Thread.sleep(100) } Now, my problem is that the program exits with a code 0 as soon as the for loop finishes execution. Thus preventing my Actors to finish there jobs. How do I get over

RemoteActor.select - result deterministic?

北城以北 提交于 2019-12-06 14:29:18
问题 I wonder if there is any determinism when calling val delegate = RemoteActor.select(). I'm asking this, because I noticed that the program doesn't terminate, when I'm sending delegates over the net. Are there any other side effects, which depend on the delegate? Are there any rules, when RemoteActor.select will return the same delegate for the same arguments? Here's some example code which demonstrates the RemoteActor.select problem: package test import scala.actors.Actor, Actor._ import

Problems with Scala Swing library

白昼怎懂夜的黑 提交于 2019-12-06 14:09:05
Hello I am having problems when using the Scala Swing library in version 2.8 Beta1-prerelease. I have a situation where I want to show a table in GUI, and update it as results are returned from a SQL request. Which way could this be done in Scala, at the moment i am using the DefaultTableModel from Java library. Another thing is that I want the table to be sortable afterwards, I cant see if Scala swing library supports this either? No - the scala swing library does not support sorting of Table - your best best is to revert to using JTable (i.e. the java swing class). A couple of things to note

Scala singleton factories and class constants

偶尔善良 提交于 2019-12-06 13:43:11
问题 OK, in the question about 'Class Variables as constants', I get the fact that the constants are not available until after the 'official' constructor has been run (i.e. until you have an instance). BUT, what if I need the companion singleton to make calls on the class: object thing { val someConst = 42 def apply(x: Int) = new thing(x) } class thing(x: Int) { import thing.someConst val field = x * someConst override def toString = "val: " + field } If I create companion object first, the 'new

Scala 2.8: how to initialize child class

扶醉桌前 提交于 2019-12-06 07:40:30
Consider the following code: abstract class X { def a:Unit a } class Y extends X { var s:String = "Hello" def a:Unit = println ("String is "+s) } This gives the following output: scala> new Y String is null res6: Y = Y@18aeabe How can I get the parent class X to wait for s to be initialized when calling a The parent's fields and the parent constructor are always initialized and run before the children's field and constructor. It means that the call to a happens before your var s is set in the child class. In general, it's a bad idea to call a virtual method from a constructor; C++ even

Scala for-comprehension returning an ordered map

╄→尐↘猪︶ㄣ 提交于 2019-12-06 03:41:25
How can I use a for-comprehension that returns something I can assign to an ordered Map? This is a simplification of the code I have: class Bar class Foo(val name: String, val bar: Bar) val myList: java.util.List[Foo] = ... val result: ListMap[String, Bar] = for { foo <- myList } yield (foo.name, foo.bar) I need to make sure my result is an ordered Map, in the order tuples are returned from the for-comprehension. With the above, I get the error: error: type mismatch; found : scala.collection.mutable.Buffer[(String,Bar)] required: scala.collection.immutable.ListMap[String,Bar] foo <- myList

What is a good library for JSON serialization for Scala 2.8.1 for use in Eclipse

最后都变了- 提交于 2019-12-06 00:31:10
I have looked at https://github.com/debasishg/sjson and using EGit I was not able to import this code for Scala 2.8.1. Ideally, this seems to be the best library that should work, but when I loaded master it is currently empty. I am trying to use Jersey ( http://jersey.java.net ) to build a REST service in Scala, but the JSON serialization is where I am stuck, as I would prefer to use something written in Scala. Unfortunately there isn't anything for Scala at http://json.org/ . So, how do I import SJSON for use in Scala 2.8.1, for Eclipse, or, is there a more updated library that would work as

Methods in trait become volatile methods when mixed in concrete classes in 2.9.0-1 but not 2.8.1

此生再无相见时 提交于 2019-12-05 17:14:44
I noticed this breaking (for me using it with OGNL) change in 2.9.0-1: I find that, in 2.9, methods declared in a trait become volatile when mixed in a class: Example in 2.9.0-1 import java.lang.reflect.Modifier trait SuperTrait { def getKnoll = "Kanutten" } class KlassWithKnoll extends SuperTrait { def getKnall = "Mars" } val qsc = classOf[KlassWithKnoll] val knollGetter = qsc.getDeclaredMethod("getKnoll") println("isVolatile: " + Modifier.isVolatile(knollGetter.getModifiers())) This prints out isVolatile: true But in 2.8.1: it prints out isVolatile: false This is actually a breaking change