4

create file test1.scala with following code:

package test
import java.io.FileInputStream
object Foo 

create another file test2.scala with following code:

package test.java
object Bar 

Now compile as scalac test1.scala test2.scala:

We get the error:

test.scala:2: error: object io is not a member of package test.java
import java.io.FileInputStream
            ^
one error found

I think the error is because Scala thinks that java above refers to package test.java. How to resolve this problem apart from renaming the package?

Jus12
  • 17,824
  • 28
  • 99
  • 157

1 Answers1

8
import _root_.java.io.FileInputStream

Or to simplify things, you might use an alias:

import _root_.java.{io => jio}
import jio.FileInputStream
Régis Jean-Gilles
  • 32,541
  • 5
  • 83
  • 97