Skip to content
Advertisement

How to use scala list and java list in the same file in scala code base?

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 is java.utils.List
  • Scala List is scala.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.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement