In Scala, importing wildcards is mandatory because many libraries expect their implicit conversions to be in scope, but they are not always convenient to name. Thus,
import collection.JavaConversions._
is a great idea, whereas
import collection.JavaConversions.{asJavaConcurrentMap,enumerationAsScalaIterator,...}
incredibly uncomfortable. Even better, in Scala you can place your import in any area:
package mypackage { class MyClass { def myGraphicalWidgetHandler { import java.awt._ ... } ... } ... }
which really helps to keep the namespace clutter in the whole file. And you can selectively rename parts of the import that, as you know, will conflict:
import java.awt.{List => AwtList, _}
Unlike Java, you are limited to the global import area, and you cannot rename them; you also do not have implicit transformations, so it’s good to only pull the things you are looking for. On the other hand, you have powerful IDE support to help you find the class you are looking for and import just that for you. So for Java, there is a reasonable argument that you should let your IDE use only what you need and not solve everything. Personally, I still find this too inconvenient and just use the import of wildcards most of the time.
Rex kerr
source share