Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unimporting in Scala

Tags:

import

scala

I heard recently some advice to "unimport an implicit conversion from Predef" - I presume that this means it is possible to unimport unwanted classes too:

import java.awt._
unimport java.awt.List

But this is not the syntax of an "unimport" (i.e. there is no such unimport keyword). What is the correct syntax?

like image 467
oxbow_lakes Avatar asked Nov 03 '09 16:11

oxbow_lakes


People also ask

What is package object in Scala?

Scala provides package objects as a convenient container shared across an entire package. Package objects can contain arbitrary definitions, not just variable and method definitions. For instance, they are frequently used to hold package-wide type aliases and implicit conversions.

How do imports work in Scala?

Import in Scala Importing packages in Scala is more flexible than in other languages. We can place import statements anywhere in the code and even hide or rename members of packages when you import them. Note: Users can either import the package as a whole or some of its member methods, classes, etc.


1 Answers

Use the import alias feature but rename the "unwanted class" to "_". Since "_" can not be accessed in Scala code as a classname, it hides the renamed class from unqualified access.

import java.awt.{List => _, _}
like image 55
Walter Chang Avatar answered Oct 03 '22 20:10

Walter Chang