w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
"scala.runtime in compiler mirror not found" but working when started with -Xbootclasspath/p:scala-library.jar
The easy way to configure the settings with familiar keystrokes: import scala.tools.nsc.Global import scala.tools.nsc.Settings def main(args: Array[String]) { val s = new Settings s processArgumentString "-usejavacp" val g = new Global(s) val r = new g.Run } That works for your scenario. Even easier: java -Dscala.usejavacp=true -jar ./scall.jar Bonus info, I happened to come across the enabling commit message: Went ahead and implemented classpaths as described in email to scala-internals on the theory that at this point I must know what I'm doing. ** PUBLIC SERVICE ANNOUNCEMENT ** If your code of whatever kind stopped working with this commit (most likely the error is something like "object scala not found") you can get it working again

Categories : Scala

Scala errors "value toInt is not a member of String" and "not found: type"
Importing scala.collection.immutable solved the problems with collections, for the classOf problem I found a workaround - using getClass instead. toInt problem remains unsolved. There is a workaround though - using the exact code from that definition: java.lang.Integer.parseInt. I have a feeling that this is also a problem with imports.

Categories : Scala

Compilation error :type mismatch found when validating sign up form passwords in scala
Contact.password is a String, but in mapping password field is a (String, String). You can not use tuple instead of String parameter in Contact.apply. You should transform your Mapping[(String, String)] to Mapping[String] like this: "password" -> tuple( "main" -> text(minLength = 6), "confirm" -> text ).verifying( // Add an additional constraint: both passwords must match "Passwords don't match", ps => ps._1 == ps._2 ).transform[String]({ps => ps._1}, {p => p -> p}) Ugly solution: mapping( ... "password" -> tuple( "main" -> text(minLength = 6), "confirm" -> text ).verifying( // Add an additional constraint: both passwords must match "Passwords don't match", ps => ps._1 == ps._2 ) ... ){ (firstname: String, la

Categories : Scala

Error with Maven/Scala: error: not found: type classOf
You're trying to input a class object (the object that represents a class) as a type identifier (the identifier of a class, consisting of its name and generic constraints in case of generic classes) . Just use VolatilityImpl directly, i.e. : class ScalaHibernateVolatilityDaoImpl(persistentClass : VolatilityImpl) This is unrelated to Maven, by the way.

Categories : Scala

Scala: How to transform a POJO like object into a SQL insert statement using Scala reflection
In your case, you can use the following codes: val o = new MyDataObj val attributes = o.getClass.getDeclaredMethods.filter { _.getReturnType != Void.TYPE }.map { method => (method.getName, method.getReturnType, method.invoke(o)) } Here I use getDeclaredMethods to get the public methods in the MyDataObj. You need to notice that getDeclaredMethods can not get methods in its parent class. For MyDataObj, getDeclaredMethods will return the following methods: public double MyDataObj.c() public boolean MyDataObj.b() public java.lang.String MyDataObj.d() public int MyDataObj.a() public void MyDataObj.c_$eq(double) public void MyDataObj.d_$eq(java.lang.String) public void MyDataObj.b_$eq(boolean) public void MyDataObj.a_$eq(int) So I add a filter to filter out irrelevant methods.

Categories : SQL

"error: can't find main class scala.tools.nsc.MainGenericRunner" when running scala in windows
Those weird variables are called parameter extensions. they allow you to interpret a variable as a path to a file/directory and directly resolve things from that path. For example, if %1 is a path to a file dir123456file.txt, %~f1 is the fully qualified path to file.txt, %~p1 is the path to the containing directory dir123456, %~s1 is the path in short name format dir123~1file.txt, and many others... Also, %0 is always set to the path of the currently running script. So: %~fs0 is the fully qualified path, in short name format, to the current script, %%~dpsi is the manual expansion of the FOR variable %%i to a drive letter (d option) followed by the path the containing folder (p option), in short format (s option). Now, this weird looking block of code is a workaround for KB83343

Categories : Windows

scala Duration: "This class is not meant as a general purpose representation of time, it is optimized for the needs of scala.concurrent."
Time can be represented in various ways depending on your needs. I personally have used: Long — a lot of tools take it directly Updated: java.time.* thanks to @Vladimir Matveev The package is designed by the author of Joda Time (Stephen Colebourne). He says it is designed better. Joda Time java.util.Date Separate hierarchy of classes: trait Time case class ExactTime(timeMs:Long) extends Time case object Now extends Time case object ASAP extends Time case class RelativeTime(origin:Time, deltaMs:Long) extends Time Ordered time representation: case class History[T](events:List[T]) Model time. Once I had a global object Timer with var currentTime:Long: object Timer { private var currentTimeValue:Long def currentTimeMs = currentTimeValue def currentTimeMs_=(newTime:Long) { ...

Categories : Scala

Why can I start the Scala compiler with "java -cp scala-library.jar;. Hello World"?
Short version: you're not using the java compiler, you're using the java runtime. Long version: there's a big difference between javac and java. javac is the java compiler, which takes in java source code and outputs jvm bytecode. java is the java runtime, which takes in jvm bytecode and runs it. But one of the great things about the jvm is that you can generate bytecode for it any which way. Scala generates jvm bytecode without any java source code.

Categories : Java

Why use template engine in playframework 2 (scala) if we may stay with pure scala
Actually you should ask this question to the dev team, however consider few points: Actually you don't need to use the Play's templating engine at all, you can easily return any string with Ok() method, so according to your link you can just do something like Ok(theDate("John Doe").toString()) Play uses approach which is very typical for other MVC web-frameworks, where views are HTML based files, because... it's web dedicated framework. I can't see nothing wrong about this, sometimes I'm working with other languages/frameworks and can see that only difference in views between them is just a language-specific syntax, that's the goal! Don't also forget, that Play is bilingual system, someone could ask 'why don't use some Java lib for processing the views?' The built-in Scala XML literals a

Categories : Scala

Scala import statement at top and inside scala class
The difference is: In Option 1 the import is viable for the complete scope. i.e any class/trait/function in com.somePackage can be used anywhere inside/outside the MyClass But in case of Option 2 it can only be used inside the MyClass and not outside it because scope of import is limited to inside MyClass only.

Categories : Scala

scala for each loop got error when convert java to scala
override def saveOrUpdateAll(entities: Collection[T]){ import scala.collection.JavaConverters._ val session: Session = getSession() for (entity <- entities.asScala) { session.saveOrUpdate(entity) } } There is no for each loop in scala. You should wrap your collection using JavaConverters and use for-comprehension here. JavaConverters wraps Collection using Wrappers.JCollectionWrapper without memory overhead.

Categories : Java

Scala Macros: Making a Map out of fields of a class in Scala
Note that this can be done much more elegantly without the toString / c.parse business: import scala.language.experimental.macros abstract class Model { def toMap[T]: Map[String, Any] = macro Macros.toMap_impl[T] } object Macros { import scala.reflect.macros.Context def toMap_impl[T: c.WeakTypeTag](c: Context) = { import c.universe._ val mapApply = Select(reify(Map).tree, newTermName("apply")) val pairs = weakTypeOf[T].declarations.collect { case m: MethodSymbol if m.isCaseAccessor => val name = c.literal(m.name.decoded) val value = c.Expr(Select(c.resetAllAttrs(c.prefix.tree), m.name)) reify(name.splice -> value.splice).tree } c.Expr[Map[String, Any]](Apply(mapApply, pairs.toList)) } } Note also that you need the c.r

Categories : Scala

scala - error: not found: value
The complete error message is error: not found: value abs. The value "abs" wan't found. You want math.abs. Alternatively you could add import math._ somewhere before you need these math functions.

Categories : Scala

Scala: Use multiple constructors from Java in Scala
Now, with the help from a workmate, i have solved that problem. Instead of classOf[Button] i have to use classOf[Button].asInstanceOf[Class[_]] With this it works fine.

Categories : Java

How to use Scala Virtualized in a Maven project with Scala-2.10?
the groupId of scala-library, scala-compiler is hard-coded into the plugin. The informations (version, ...) of scala-compiler are computed from the scala-library dependencies. You can open a ticket and ask to support other groupId (may be configurable one or not hard-coded). You can fork, made the change, and submit a patch / pull request. UPDATE : scala-mavent-plugin 3.1.6 include the patch from evantill (thanks) So you can override the default scalaOrganization

Categories : Scala

Scala: Use Java Constructor with Subclasses in Scala
Why are you using classOf[FXTaskStackElement].asInstanceOf[Class[_]] instead of just classOf[FXTaskStackElement]? Since your second argument is a Class[_], there is no suitable SUBCLASS.

Categories : Java

I have to compile hello.scala which has a import command "org.scala._"
Include the package name when using the scala command and run it against the class file instead of the source code scala org.scala.Hello Like Java, Scala Naming conventions indicate that classes start with an initial uppercase letter for classes, e.g. Hello

Categories : Java

Convert Java Object (that is really a Scala Map) to Scala Map
You are probably trying to cast across class loaders. You can't do this--each class loader maintains its own hierarchy (for those classes not passed off to a common parent loader). Try calling getClassLoader on both your returned map and on a freshly-created one. Incidentally, Map$Map2 is just an implementation detail--a subclass of Map for dealing with two-element maps. It casts just fine normally: scala> val m = Map(1->"one", 2 -> "two"): Object m: Object = Map(1 -> one, 2 -> two) scala> m.getClass res0: Class[_ <: Object] = class scala.collection.immutable.Map$Map2 scala> m.asInstanceOf[scala.collection.immutable.Map[Int,String]] res1: scala.collection.immutable.Map[Int,String] = Map(1 -> one, 2 -> two)

Categories : Scala

Scala Yield behaves differently than Scala Map
var characterMap = (for (_ <- 0 until sizeX*sizeY) yield Nil).toArray[List[ActorRef]] Is translated into: var characterMap = (0 until sizeX*sizeY).map(_ => Nil).toArray[List[ActorRef]] and this should work. Nit-picking: They are not equivalent, they are the same. for is just sugar syntax. By the way, you might want to consider: Array.fill[List[ActorRef]](sizeX*sizeY)(Nil)

Categories : Arrays

Tilde in Scala found in Scalatra example code
In Scala: ~x translates to x.unary_~ (this also applies to +,- and ! as explained in this post). So your example translates to: add(newTodo(c.name.value.unary_~)) The documentation can hence be found at the type of value.

Categories : Scala

Scala type mismatch: default.type (with underlying type A1 => B1)
Strange, as soon as I renamed default variable, everything compiled fine: scala> def composeHandlingFuture[T](fut: Future[T], x: T): Future[T] = | fut recover { case e: Exception => x } composeHandlingFuture: [T](fut: scala.concurrent.Future[T], x: T)scala.concurrent.Future[T]

Categories : Scala

Scala: higher-kinded types, type projections and type mismatch error
@ziggystar says it: Drop the bound B and use M[X] directly: class TransM[X[_]](val b: M[X]) extends M[CurriedTrans[X, M[X]]#Type] { def from[A](f: T[A]) = b.from(f.r).get } val x1 = new TransM(new ListM) You could consider to do the same for Trans and CurriedTrans. If you need the inner type of M, you can always expose it through a type member of Trans and CurriedTrans.

Categories : Scala

scala type error for class with map member typed with existential type
Unless you explicitly require getting the keys back out as the statically correct subtype (which seems unlikely), then the following will work: case class DictVariant1(data: Map[MyBaseType, Double]) val d = List((Concrete1() : MyBaseType, 3.5)).toMap val dv1 = DictVariant1(d) Using a type ascription forces Concrete1() to be seen as an instance of the base type; you'd get the same effect if you added an explicit type to d: val d : Map[MyBaseType, Double] = .... Or if you put multiple entries in such that the type inferencer picks the base type: val d = List((Concrete1(), 3.5), (Concrete2(), 4.5)).toMap The 'get' you use is always going to fail, however, because you're trying to use the whole Map as an index: it works fine if you provide a sensible key: dv1.data.get(Concrete1())

Categories : Scala

Scala Type Mismatch underlying type and class vs method
The problem in your code is type parameter shadowing. You have: class ThreeStacks[A, B, C](val stackSize:Int = 1000) { def push1[A](value: A): Unit = stack1.push(value) ... } It should be: class ThreeStacks[A, B, C](val stackSize:Int = 1000) { def push1(value: A): Unit = stack1.push(value) ... } The way you have done it, type parameter A of class ThreeStacks and type parameter A of method push1 are completely different ones and thus, are incompatible with each other. The same applies to B and C.

Categories : Scala

Scala play - "not found: value routes" (Eclipse and IDEA)
Since there seems to be no answer, I'll at-least describe my workaround: Instead of using <link href=@routes.Assets.at("stylesheets/style.css") rel="stylesheet" type="text/css" /> in my template HTML, I'm using <link href="assets/stylesheets/styles.css") rel="stylesheet" type="text/css" /> Since I'm not invoking routes.Assets.at, there is no issue with not finding the value routes. (However, I'm guessing this workaround will easily crumble when I would have need of more complex templates)

Categories : Scala

Scala Structural type and existential type issue
I think it's an inference bug (or maybe a limitation) concerning the type construct. Edit: the error message was the first thing that made me think it was a bug: "type mismatch; found : Int(1) required: A" If you split the last line in to 2, i.e. val t3 = TMap(1,2) val t2: MapT2[Int] = t3 , then it produces a similarly pongy message: "type mismatch; found : Test1.this.TMap[Int,Int] required: Test1.this.MapT2[Int] (which expands to) Test1.this.TMap[A,A]" Given that A is a 'symbol' and Int is a class, it seems like it's comparing apples and oranges. Sorry I can't take this logic any further!

Categories : Scala

Compile error in scala template while passing an arraylist: Not found value
My guess is that the import statement has to be below the parameter statement. Try switching the order of @import models.com.contactmanager.Profile @(profiles: List[Profile]) to @(profiles: List[Profile]) @import models.com.contactmanager.Profile

Categories : Scala

Scala compiler says "error: identifier expected but integer literal found." for () not {}
When you write an expression c:Char => 1, Scala compiler treats it as c:(Char => 1), that is, a function variable c with type Char => 1. However, 1 is not a valid type (or type variable), so Scala compiler complains. So you need to write s.toList map ((c:Char) => 1) to help the compiler out of the type association. {c:Char => 1} creates a function literal, that is, a function that accepts a char and returns 1. So s.toList map {c:Char => 1} is the same as s.toList map({c:Char => 1}) // or val fn = {c: Char => 1} s.toList map fn However, it seems that Scala doesn't have special specification for the {c:Char => blabla} form for creating function literals. I think it is because that there is {some_var: SomeType => *Class Definition* } form in class defin

Categories : Scala

Scala type deferring
How to fix a error You have to add an implicit parameter to your method like this: def buildJsArray[T](l: List[T])(result: JsArray)(implicit tjs: Writes[T]): JsArray There is such parameter in the Json.toJson method. The reason why you have to add this parameter is that you know how to convert T to json only when you know what T is. It means you have the method to serialize T only when you call buildJsArray and this parameter allows you to pass this serialization method to the method buildJsArray. How to build a JSArray You could just use a constructor of JsArray. It takes a Seq[JsValue]: new JsArray(l.map{Json.toJson(_)}) There is already an implicit Writes for Traversable so you don't need your own method buildJsArray, you could just use method Json.toJson with parameter of typ

Categories : Scala

class java.lang.RuntimeException/Scala class file does not contain Scala annotation
Looks like the library is configured to compile against Scala 2.9.1. Major versions of Scala are not binary compatible. I put the necessary SBT changes here: https://github.com/mpartel/prestashop-scala-client/commit/e9a1df40bfe35518aaebac899e438b9b6fa6d728

Categories : Scala

Scala type comparison not working
See the issue recorded here At the moment isInstanceOf/asInstanceOf don't support (upper bounded) type parameters so it parametric polymorphism is not possible even if the type parameter has a manifest.

Categories : Scala

Scala and type bound with a given operation
Sure, it's possible with a structural type, and you've even almost got the syntax right: def foo(x: { def apply(): Double }) = x.apply And then: scala> foo(() => 13.0) res0: Double = 13.0 Or: scala> foo(new { def apply() = 42.0 }) res1: Double = 42.0 The definition of foo will give you a warning about reflective access, which you can avoid by adding an import or compiler option (as described in the warning message). Note that there is some overhead involved in calling methods on a structural type, so if you need this in a tight inner loop you may want to rethink your approach a bit. In most cases, though, it probably won't make a noticeable difference.

Categories : Scala

How to find the type of a Scala expression
In the scala console, you can use :type: :type x+y At runtime (including in the console) you can do: scala> import reflect.ClassTag import reflect.ClassTag scala> def exprType[T:ClassTag]( x: T ) = implicitly[ClassTag[T]] exprType: [T](x: T)(implicit evidence$1: scala.reflect.ClassTag[T])scala.reflect.ClassTag[T] scala> exprType( x+y) res1: scala.reflect.ClassTag[String] = java.lang.String exprType will return the ClassTag the parameter. Because ClassTag are not resilient to erasure, you might want to use a TypeTag instead (but this requires to have "scala-reflect.jar" in the classpath): import reflect.runtime.universe._ def exprType[T:TypeTag]( x: T ) = implicitly[TypeTag[T]]

Categories : Scala

Varargs with different type parameters in scala
This can't be done. Consider this: val key = readStringFromUser(); val value = bar(key); what would be the type of value? It would depend on what the user has input. But types are static, they're determined and used at compile time. So you'll either have to use a fixed number of arguments for which you know their types at compile time, or use a generic vararg and do type casts during runtime.

Categories : Scala

Scala's "clean up" of type erasure
Well, the quote says “cleans up”, not “eliminates”. Type erasure is still there and it can bite you. Scala has Manifests. Manifest is an object containing information about your actual type. Here is a nice answer about Manifests.

Categories : Scala

why does scala toString give type Any?
What happens if q >= 3 ? What type does if return then ? e.g. if you write this: if (qqq < 0) "a" else "b" you'll always get a String return type

Categories : String

Scala continuation type error
You already figured out you need to change cps with cpsParam. If you compile the line outside of the REPL inside an object, it will actually work fine. What you see is an artifact of what the REPL does behind the scene to print out the evaluation of what it reads. In the REPL when you type and see something like: scala> def f() = 1 f: ()Int For some reason that I cannot explain, the code that generates the f: ()Int string assigns the result of f to a dummy variable like this: lazy val $result = f. You can see it in action if you start the REPL with the -Xprint:parser option. It will expose a lot of what happens behind the scene. Unfortunately that code that creates the dummy assignment does not understand the continuation plug-in and the synthetized code is not valid. To work arou

Categories : Scala

Type mismatch in scala with wildcards
Without further information this answer is only a guess based on the error: type mismatch; found : TBase[_$1,_$2] where type _$2, type _$1 required: TBase[_ <: TBase[_, _], _ <: TFieldIdEnum] Constraining the type arguments as the error message suggested may fix the problem: def serialize(base: TBase[_ <: TBase[_,_] ,_ <: TFieldIdEnum]) It's hard to tell why this would be case, without seeing the signatures of the serialize methods and the TBase class. I can only speculate that the java wildcards brings the constraint already defined somewhere else, while the scala existencials doesn't, requiring that you state than explicitly. Also, don't use the return keyword. It doesn't do what you think it does.

Categories : Java

Scala Advanced Type Usage
Without more details on your DSL, I'm afraid it's not clear what you mean by "access the tuple types statically". Here's a simplified version of the API that has no trouble with tuple types: class Event[T] { def joinOn[T2, R](ev2: Event[T2])(f: (T, T2) => R) = new Event[R] } You can use this as follows: val e1 = new Event[(Int, String)] val e2 = new Event[(Int, String)] val e3 = e1.joinOn(e2)(_._1 == _._2) It should be easy to see how this could be extended to supporting your join/windowLength/on syntax. Update: I can see that your use case is complicated by the fact that you need to translate the Scala-encoded query expression to another query language. In this case, you want the on method's signature to look like: def on[T2, R](f: (Expr[T], Expr[T2]) => Expr[R]): Event[R

Categories : Scala

Scala: how do I access a Class[?0] type?
You are barking at the wrong tree. :) The method return type is Class[_] -- a Class whose type parameter may be anything, but you do not need to know the type parameter: the class is what you want! You can just get its string representation, for example: scala> attributes(0)._2.toString res3: String = boolean scala> attributes(1)._2.toString res4: String = class java.lang.String Or you can get the canonical name: scala> attributes(0)._2.getCanonicalName res7: String = boolean scala> attributes(1)._2.getCanonicalName res8: String = java.lang.String

Categories : Scala



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.