Skip to content

Code for _root_ import #1377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.baeldung.scala.rootimport

import org.scalatest.flatspec.AnyFlatSpec

class RootImportUnitTest extends AnyFlatSpec {

it should "use the custom List when using relative import" in {
import scala.*
val myList: scala.List = List(100)
assert(myList.toString == "MyList[100]")
}

it should "use the scala collection List when using root import" in {
import _root_.scala.*
val scalaList: List[Int] = List(100)
assert(scalaList.toString == "List(100)")
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.baeldung.scala.rootimport.scala

class List(val num: Int) {
override def toString: String = s"MyList[${num}]"
}

object List {
def apply(num: Int) = new List(num)
}