Skip to content

Commit ed2aaa3

Browse files
Merge pull request #1377 from yadavan88/root-import
Code for _root_ import
2 parents 1fda1a5 + 62a3088 commit ed2aaa3

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.scala.rootimport
2+
3+
import org.scalatest.flatspec.AnyFlatSpec
4+
5+
class RootImportUnitTest extends AnyFlatSpec {
6+
7+
it should "use the custom List when using relative import" in {
8+
import scala.*
9+
val myList: scala.List = List(100)
10+
assert(myList.toString == "MyList[100]")
11+
}
12+
13+
it should "use the scala collection List when using root import" in {
14+
import _root_.scala.*
15+
val scalaList: List[Int] = List(100)
16+
assert(scalaList.toString == "List(100)")
17+
}
18+
19+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.baeldung.scala.rootimport.scala
2+
3+
class List(val num: Int) {
4+
override def toString: String = s"MyList[${num}]"
5+
}
6+
7+
object List {
8+
def apply(num: Int) = new List(num)
9+
}

0 commit comments

Comments
 (0)