This pertains to calling Scala code from Java or vice-versa.
Questions tagged [scala-java-interop]
332 questions
0
votes
4 answers
How to concatenate a list to another list in scala
Here i use to concatenate 2 Lists (with same type) using this :+
and the code is testResult :+ studentsearch
the length of the list get value zero in the console
Controller
@RequestMapping(value = Array("parent/ViewReports.html"))
def…

Prasanth A R
- 4,046
- 9
- 48
- 76
0
votes
1 answer
Apache collections UnmodifiableSet to scala immutable Set
What should I do when I get this?
java.lang.ClassCastException: org.apache.commons.collections.set.UnmodifiableSet
cannot be cast to scala.collection.immutable.Set

Anton
- 494
- 5
- 19
0
votes
3 answers
Scala function to accept Java maps from Java code
I have a mixed Scala/Java project. I'm trying to write a Scala function that would accept either Scala maps (from Scala code) or Java maps (from Java code) - java.util.HashMap for a start.
Here's what I came up with (Scala code):
def test[M <:…

Alex
- 82
- 9
0
votes
1 answer
Should I use collectionAsScalaIterable({java collection}) or Seq({java collection}).flatten?
We're starting to use Scala Test to test our Java application, and I want to test the contents of a Java Collection. We came up with 2 possibilities:
JavaConversions.collectionAsScalaIterable(getJavaCollection()) must contain(allOf(item1,…

Bernie
- 2,253
- 1
- 16
- 18
0
votes
0 answers
How to access a Java inherited field with the same name as a Scala method?
I'm having a Scala trait A with an abstract method
trait A[T] {
def self: T
}
Now it happened me that I want to extends a Java class not under my control with a field with the same name:
public class B {
protected T self;
}
I'd like to…

Petr
- 62,528
- 13
- 153
- 317
0
votes
1 answer
java Constructor can not convert to scala
i know java Constructor convert into Scala code. but this is my project Generic class implementation. i am using hibernate ,spring in this project and i create genericDAO trait but can't create It's implementation or i can't convert this java…

Prasanth A R
- 4,046
- 9
- 48
- 76
0
votes
1 answer
Is there anyway to create a new Scala object from a Java Class
I have a number of use cases for this, all around the idea of interop between existing Java libraries and new Scala Code. The use case I've selected is the easiest I think.
Use Case:
I working on providing a JUnit Runner for some scala tests (so…

Stave Escura
- 2,058
- 1
- 19
- 24
0
votes
1 answer
Scala types/collections when interfacing with Java and vice versa
When interfacing with a scala library in java, or a java library in scala, are there certain types or collections that don't map efficiently such that you have to perform "expensive" operations to perform a conversion?
e.g. memory wise you might…

loyalflow
- 14,275
- 27
- 107
- 168
0
votes
2 answers
Call Java method with alternatives from Scala
I am trying to use the put method of the ContentValues class in the Android API from Scala, but I can't figure out a way to make Scala narrow down the type of list elements. For example :
val a: List[(String, Any)](...)
val cv = new…

F.X.
- 6,809
- 3
- 49
- 71
0
votes
1 answer
Convert List into Seq[(String,String)]
I want to use @helper.select form Play 2 template engine where I should specify Seq[(String,String)] containing data for . But I have List. And I know rather weakly Scala.
Without this helper I populate

nickotinus
- 323
- 5
- 17
0
votes
1 answer
How can I call a Scala function taking a PartialFunction with a Unit return type from Java?
I'm trying to use the scaffolding described by oxbow_lakes in What is the easiest way to implement a Scala PartialFunction in Java? to call a Scala method that takes a PartialFunction. Here's my Scala code:
class MyScalaClass {
def…

Josh Glover
- 25,142
- 27
- 92
- 129
0
votes
1 answer
Accessing Scala standalone singleton object from Java
I am having trouble accessing the method fromString in Scala. I tried javap and at least one of the ways i am accessing should be working, but its not.
App.scala
object App {
def fromString(s:String) : Option[Int] = if( s == "0" ) Some(0) else…

smartnut007
- 6,324
- 6
- 45
- 52
0
votes
2 answers
Intellij idea cannot resolve dollar containing classes
Here the problem: I have jar containing compiled scala code. In jar I see
Step.class
Step$class.class
which both are legal java classes.
However when I try to use Step$class in Intellij Idea java project it says: "Cannot resolve symbol Step$class".…

Vladimir
- 12,753
- 19
- 62
- 77
-1
votes
1 answer
A function to convert java map to scala map
Totally new to scala so any help is appreciated. I'm trying to pass objects from python to scala via the JVM, so I need a function that takes a java map as an input and returns a scala map as output.
I'm not really sure yet if I want the map to be…

Molly
- 49
- 4
-1
votes
2 answers
Scala Java interoperability with val
In scala, if we have a class say,
case class B(b: Int)
object B {
def main(args: Array[String] {
val b = B(1)
b.b = 2 // ** compile time error here **
}
}
would give an error saying, when compile with scalac B.scala
error:…

user2829759
- 3,372
- 2
- 29
- 53