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?
import _root_.java.io.FileInputStream
Or to simplify things, you might use an alias:
import _root_.java.{io => jio}
import jio.FileInputStream
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With