object Top{
object A
class B
trait C
}
import Top.{A, C} // imports A and C from Top packageIt's possible to import all in one go with underscore '_'.
import Top._ // imports A, B, CWhat if we have a clash of names, e.g. 'A' is used in two paths.
object Top2{ object A }We can import and rename the other one (the new name is alias for the long name in that scope):
import Top.AWhat if we need to import all but, say two classes. We could have lots of classes to explicitly type if we do it importing class by class; just using underscore would import also unwanted classes so it is not an option.
import Top2.{A => OtherA}
We can rename the unwanted to _, which in practice means that the naming is ignored, so effectively it's not imported at all. Let's pretend we have lots of classes in Top1, and we don't need just B and C.
import Top.{B => _, C => _, _}The last '_' tells to compiler to import all the others.
1 comment:
good examples, thanks! :)
Post a Comment