I have a use case where I want to use scala list and java list in the same file in scala codebase. I am using java list by importing java.util.list. Now If I want to use the scala list in the same file, it’s taking that list as java list and throws an error.
Advertisement
Answer
You can use Fully Qualified Name (FQN)
- Java
List
isjava.utils.List
- Scala
List
isscala.collection.immutable.List
You also use alias:
import scala.collection.immutable.{List=>ScalaList} import java.utils.{List=>JavaList}
Now you can refer to them as ScalaList
and JavaList
.