This pertains to calling Scala code from Java or vice-versa.
Questions tagged [scala-java-interop]
332 questions
                    
                    208
                    
            votes
                
                4 answers
            
        What is the difference between JavaConverters and JavaConversions in Scala?
In scala.collection, there are two very similar objects JavaConversions and JavaConverters. 
What is the difference between these two objects? 
Why do they both exist?
When do I want to use one vs. the other?
         
    
    
        Michael Ekstrand
        
- 28,379
- 9
- 61
- 93
                    165
                    
            votes
                
                5 answers
            
        What's the difference between == and .equals in Scala?
What is the difference between == and .equals() in Scala, and when to use which?
Is the implementation same as in Java?
EDIT: The related question talks about specific cases of AnyVal. The more general case is Any.
         
    
    
        Jus12
        
- 17,824
- 28
- 99
- 157
                    134
                    
            votes
                
                9 answers
            
        How to convert a scala.List to a java.util.List?
How to convert Scala's scala.List into Java's java.util.List?
         
    
    
        Alex Baranosky
        
- 48,865
- 44
- 102
- 150
                    116
                    
            votes
                
                9 answers
            
        Iterating over Java collections in Scala
I'm writing some Scala code which uses the Apache POI API. I would like to iterate over the rows contained in the java.util.Iterator that I get from the Sheet class. I would like to use the iterator in a for each style loop, so I have been trying to…
         
    
    
        BefittingTheorem
        
- 10,459
- 15
- 69
- 96
                    115
                    
            votes
                
                5 answers
            
        How to convert a java.util.List to a Scala list
I have this Scala method with below error. Cannot convert into a Scala list.
 def findAllQuestion():List[Question]={
   questionDao.getAllQuestions()
 } 
type mismatch; found : java.util.List[com.aitrich.learnware.model.domain.entity.Question]…
         
    
    
        boycod3
        
- 5,033
- 11
- 58
- 87
                    65
                    
            votes
                
                2 answers
            
        Using Scala traits with implemented methods in Java
I guess it is not possible to invoke methods implemented in Scala traits from Java, or is there a way? 
Suppose I have in Scala:
trait Trait {
  def bar = {}
}
and in Java if I use it as 
class Foo implements Trait {
}
Java complains that Trait is…
         
    
    
        Jus12
        
- 17,824
- 28
- 99
- 157
                    60
                    
            votes
                
                4 answers
            
        Converting Java to Scala durations
Is there an elegant way to convert java.time.Duration to scala.concurrent.duration.FiniteDuration?
I am trying to do the following simple use of Config in Scala:
val d = ConfigFactory.load().getDuration("application.someTimeout")
However I don't see…
         
    
    
        Jacob Eckel
        
- 1,633
- 1
- 13
- 22
                    60
                    
            votes
                
                3 answers
            
        How can I convert a Java Iterable to a Scala Iterable?
Is there an easy way to convert a    
java.lang.Iterable[_]
to a
Scala.Iterable[_]
? 
         
    
    
        Matt R
        
- 9,892
- 10
- 50
- 83
                    50
                    
            votes
                
                4 answers
            
        Convert Java Map to Scala Map
I have a java map: java.util.Map>
and I would like to convert it to the scala map: Map[SomeObject, Set[OtherObject]]
I have used mapAsScalaMap but the result is not quite what I want, the result is:… 
        user365268
                    49
                    
            votes
                
                4 answers
            
        Using Scala from Java: passing functions as parameters
Consider the following Scala code:
package scala_java
object MyScala {
  def setFunc(func: Int => String) {
    func(10)
  }
}
Now in Java, I would have liked to use MyScala as:
package scala_java;
public class MyJava {
    public static void…
         
    
    
        Jus12
        
- 17,824
- 28
- 99
- 157
                    45
                    
            votes
                
                7 answers
            
        Convert Java List to Scala Seq
I need to implement a method that returns a Scala Seq, in Java.
But I encounter this error:
java.util.ArrayList cannot be cast to scala.collection.Seq
Here is my code so far:
@Override
public Seq columnNames() {
    List a = new…  
         
    
    
        Fundhor
        
- 3,369
- 1
- 25
- 47
                    41
                    
            votes
                
                4 answers
            
        How can I convert Scala Map to Java Map with scala.Float to java.Float k/v conversion
I would like to be able to perform the following, but it fails in the call to useMap. How can I perform this conversion?
scala> import scala.collection.JavaConversions._
import scala.collection.JavaConversions._
scala> import…
         
    
    
        rvange
        
- 2,432
- 2
- 20
- 23
                    40
                    
            votes
                
                5 answers
            
        How to use scala.None from Java code
Possible Duplicate:
Accessing scala.None from Java 
In Java you can create an instance of Some using the constructor, i.e. new Some(value), but None has no partner class.  How do you pass None to a Scala function from Java?
         
    
    
        Craig B.
        
- 553
- 1
- 4
- 10
                    40
                    
            votes
                
                2 answers
            
        How can I use a Scala singleton object in Java?
I have a Scala object that I need to use in a Java class. 
Here's the Scala object
object Person {
  val MALE = "m"
  val FEMALE = "f"
}
How can I use this Scala object in Java?
I have tried the following so far without success (compile…
         
    
    
        user786045
        
- 2,498
- 4
- 22
- 18
                    38
                    
            votes
                
                1 answer
            
        Using a Java library with Scala reserved words
I'm using an external library written in Java (Selenium). One of the function calls has the signature type(String, String), and I keep getting compiler errors when trying to call it from Scala, that is:
selenium.type("ab","abc")
Is there a…
         
    
    
        John
        
- 479
- 4
- 6