scala-2.8

How to call a function that has a Map with a Generic Type as a parameter

I'm using Scala to do typesafe JPA2 Criteria Queries. Therefore i have a Java MetaModel Class (the only Java in my code, the rest is Scala -> pure Scala problem), which holds my model attributes: @StaticMetamodel(User.class) public class User_ { public static volatile SingularAttribute<User, Long> id; public static volatile Singula...

How to define a parameterless constructor in Scala

This question is so stupid... Anyway, i just can't find the right information, because every Scala-constructor example class i see works with at least one parameter. I want to have this class translated from Java to Scala: public class SubscriptionConverter extends Converter { public SubscriptionConverter() { Context ctx = new In...

Pimp my function in scala - applying implicit conversions on functions

I have some problems when I want to use implicit methods to convert a function to something else. I'm implementing a small DSL in Scala 2.8 for testing purposes. It should support various checks (assertions if you like) on instances. The whole DSL is a bit complex, but the following simplified example shows my problem: object PimpMyFun...

Convert a Scala Buffer to Java ArrayList

In my Scala function, i'm traversing a Java ArrayCollection, extracting specific elements which should form a new collection. At the end, it has to be a Java-ArrayList again, because i'm interacting with a Java Framework. My Code: // to make scala-style iterating over arraylist possible import scala.collection.JavaConversions._ // Arra...

Scala collection: totally unpredictable behaviours...

Have been pretty frustrated by Scala 2.8 collection behaviours. Here's the problem: I'm creating a Sudoku board. I'm labelling the cells from A1 to I9 (the letters being the rows and the digits being the columns). I want to get a list of units on the board, which is the 9 rows, the night columns, and the night quadrants. Here's my scala...

ProcessBuilder - Start another process / JVM in Scala - HowTo?

I already handled to start another VM in Java. See ProcessBuilder - Start another process / JVM - HowTo? For some reason, I can't manage to do the same in Scala. Here's my code object NewProcTest { def main(args :Array[String]) { println("Main") // val clazz = classOf[O3] val clazz = O4.getClass Proc.spawn(clazz, true...

Is there a way of creating an IdentityMap in scala 2.8

There used to be an IdentityHashMap in collection.jcl: is there a way of constructing the same thing in the new 2.8 collections library (perhaps with a bespoke equality-relation)? ...

RemoteActor.select - result deterministic?

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 delega...

Scala Remote Actors - Pitfalls

While writing Scala RemoteActor code, I noticed some pitfalls: RemoteActor.classLoader = getClass().getClassLoader() has to be set in order to avoid "java.lang.ClassNotFoundException" link doesn't always work due to "a race condition for which a NetKernel (the facility responsible for forwarding messages remotely) that backs a remote ...

Stream of readLines

I'm attempting to create an infinite stream of strings from readLine calls: import java.io.{BufferedReader, InputStreamReader} val in = new BufferedReader(new InputStreamReader(System in)) val input: Stream[String] = Stream.cons(in readLine, input) But it appears that the readLine call isn't being called lazily. Immediately after ente...

Move the implementation of a generic method to an abstract super class

EDIT: Rewrote the question. Added bounty as its important for me. The final hint with which i can get findByAttributes to work (without reimplementing it in subclasses) will get my points. In my app i'm doing typesafe database queries with the new JPA2 Criteria Query. Therefore I have a trait DAO which should be (re)usable for ALL entit...

Scala swing 2.8 how do I set the background color of a Slider ?

Hi, How can I set the background color of a Slider in Scala Swing 2.8 final. I copied the UIDemo object provided in the distribution for my tests and added background = java.awt.Color.RED but that does not take effect on my mac. object UIDemo extends SimpleSwingApplication { ... object slider extends Slider { min = 0 value = tab...

Scala: How to wait for a Actor/Reactor to be terminated

Hi there! I'm looking for some way to (busy) wait for an Actor (or Reactor) to be terminated, i.e. make sure that all messages sent before some Stop() message are consumed. What I came up so far with is setting up a CountDownLatch on which I can wait for the Stop() message to be processed. This approach seems to work, although I'm not ...

Confusion with a simple Scala packaging example

I've been experiencing confusion over packaging classes in Scala and importing packages. Let me start with a pair of simple source files: file: a/A.scala package a // Which of these imports should be used? They both seem to work. //import a.b._ import b._ class A { val fieldB = new B } file: a/b/B.scala package a.b class B u...

program hangs when using multiple futures with multiple remote actors

I start two remote actors on one host which just echo whatever is sent to them. I then create another actor which sends some number of messages (using !! ) to both actors and keep a List of Future objects holding the replies from these actors. Then I loop over this List fetching the result of each Future. The problem is that most of the ...

how to use new scala 2.8.0 nested annotations

Hi folks, looks like when scala 2.8.0 is out, we can use nested @annotations in our persistence layers. But how? Can anyone please transform this from java to scala? Thanks. @NamedQueries({ @NamedQuery(name = "findAll", query="select p from Person p"), @NamedQuery(name = "findTheOne", query="select p from Person p where...

A problem of implicit conversions in scala 2.8

I want to write a implicit conversion of Tuple2[A,B] to Seq[C] where C is super type of both A and B. My first try as following: implicit def t2seq[A,B,C](t: (A,B))(implicit env: (A,B) <:< (C,C)): Seq[C] = { val (a,b) = env(t) Seq(a,b) } But it doesn't work: scala> (1,2): Seq[Int] <console>:7: error: type mismatch; found :...

Package objects

Could someone please explain package objects, not so much the concept but their usage. I've tried to get an example working and the only form I got to work was as follows: package object investigations { val PackageObjectVal = "A package object val" } package investigations { object PackageObjectTest { def main(args: Array[...

Scala method that returns multiple concatenated filter functions

In my app, I'm filtering a file array by various types, like the following: val files:Array[File] = recursiveListFiles(file) .filter(!_.toString.endsWith("png")) .filter(!_.toString.endsWith("gif")) .filter(!_.toString.endsWith("jpg")) .filter(!_.toString.endsWith("jpeg")) .filter(!_.toString.endsWith("bmp")) .filter(!_.toSt...

What do <:<, <%<, and =:= mean in Scala 2.8, and where are they documented?

I can see in the API docs for Predef that they're subclasses of a generic function type (From) => To, but that's all it says. Um, what? Maybe there's documentation somewhere, but search engines don't handle "names" like "<:<" very well, so I haven't been able to find it. Follow-up question: when should I use these funky symbols/classe...