I'm currently trying to "translate" the following Java class to an equivalent Scala class. It's part of a JavaEE6-application and i need it to use the JPA2 MetaModel.
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.StaticMetamodel;
@StaticMetamodel(Person.class)
public class Person_ {
public s...
What is the difference between sealed abstract and abstract Scala class?
...
I tried to create abstract turn based Game and abstract AI:
abstract class AGame {
type Player
type Move // Player inside
def actPlayer : Player
def moves (player : Player) : Iterator[Move]
def play (move : Move)
def undo ()
def isFinished : Boolean
def result (player : Player) : Double
}
abstract class Ai[Game <: ...
Hi chaps,
I hit a bit of a quirk of scala's syntax I don't really understand
object Board {
def getObjectAt(x:Int, y:Int):Placeable = return locations(x)(y)
}
works fine. But
object Board {
def getObjectAt(x:Int, y:Int):Placeable {
return locations(x)(y)
}
}
returns the error
Board.scala:8: error: illegal start of d...
I was wondering whether the standard Scala parser combinators contain a parser that accepts the same identifiers that the Scala language itself also accepts (as specified in the Scala Language Specification, Section 1.1).
The StdTokenParsers trait has an ident parser, but it rejects identifiers like empty_?.
(If there is indeed no such...
I've seen (and heard) quite a bit of noise about adding virtual classes to Scala (it already has virtual types, according to Martin Odersky).
Could someone provide a layman's perspective (perhaps with an example) on what a virtual type is and what could be possible were scala to have virtual classes?
[I have no experience with C or C++...
Hi
I am Peter Pilgrim. I watched Martin Odersky create a control abstraction in Scala. However I can not yet seem to repeat it inside IntelliJ IDEA 9. Is it the IDE?
package demo
class Control {
def repeatLoop ( body: => Unit ) = new Until( body )
class Until( body: => Unit ) {
def until( cond: => Boolean ) {
body;
...
say, I have the following:
trait SomeTrait {
def someMethod: String;
}
object SomeObject extends SomeTrait {
def someMethod = "something";
}
I would like to call "someMethod" using reflection as I have the object name as a String.
Something like:
val objectName = "SomeObject"
val someTrait:SomeTrait = ???.asInstanceOf[SomeTr...
Do any Scala testing libraries help with performance tests? Can't find anything relevant in ScalaTest or specs.
...
I've written a little library that uses implicits to add functionality that one only needs when using the REPL in Scala. Ruby has libraries like this - for things like pretty printing, firing up text editors (like the interactive_editor gem which invokes Vim from irb - see this post), debuggers and the like. The library I am trying to wr...
One handy feature of Scala is lazy val, where the evaluation of a val is delayed until it's necessary (at first access).
Ofcourse a lazy val must have some overhead - somewhere Scala must keep track of whether the value has already been evaluated and the evaluation must be synchronized, because multiple threads might try to access the v...
After reading some OpenJDK mailinglist entries, it seems that the Oracle developers are currently further removing things from the closure proposal, because earlier design mistakes in the Java language complicate the introduction of the Java closures.
Considering that Scala closures are much more powerful than the closures planned for J...
I need a back-check (please).
In an article ( http://www.win-vector.com/blog/2010/06/automatic-differentiation-with-scala/ ) I just wrote I stated that it is my belief in Scala that you can not specify a function that takes an argument that is itself a function with an unbound type parameter. I have edited this question to try and si...
Hi,
I have a pair of loops over a nested array object in scala
def populateBoard(data:Array[Array[Char]]) {
Board.resize(data(0).length, data.length)
for(y <- 0 to data.length-1) {
val row = data(y)
for(x <- 0 to row.length-1) {
Board.putObjectAt(x,y,GamePieceFactory.createInstance(row(x),x,y))
...
When you create a case class, the compiler creates a corresponding companion object with a few of the case class goodies: an apply factory method matching the primary constructor, equals, hashCode, and copy.
Somewhat oddly, this generated object extends FunctionN.
scala> case class A(a: Int)
defined cla...
Hello to everyone. I came across with an error on my Scala code that I cannot solve by myself (I am new at Scala).
I have the following code:
def myFunction(list: List[Any]): String = {
var strItems : String = "";
list.foreach(item => {
strItems += item match {
case x:JsonSerializable => x.toJson()
case y:String => (...
I would like to add to all collections where it makes sense, an argMax method.
How to do it? Use implicits?
...
Let's say I have this code:
val string = "one493two483three"
val pattern = """two(\d+)three""".r
pattern.findAllIn(string).foreach(println)
I expected findAllIn to only return 483, but instead, it returned two483three. I know I could use unapply to extract only that part, but I'd have to have a pattern for the entire string, something...
Is there any way to create something similar to this:
class F[A] {def apply(a: A) = println(a)}
So that I can:
(new F[Int*])(1,2,3)
UPDATE: but otherwise, I want F to accept normal parameters:
(new F[Int])(1)
...
I have a simple FunSuite-based ScalaTest:
package pdbartlett.hello_sbt
import org.scalatest.FunSuite
class SanityTest extends FunSuite { ...