In my opinion, one of the greatest things about Scala is its interoperability with Java and its similar syntax. One thing that I found strange is the use of the _ operator for package wilcard imports instead of the * operator that is used in Java.

Is there a technical reason for using _ instead of *? If not, then why was this change done?

  • This might just be a functional thing. I know Haskell uses _ in a few places to act as a wildcard/not-specified value.
    – KChaloux
    Apr 11, 2013 at 19:17

4 Answers 4


In Scala, the * is a valid identifier. One could write:

val * = "trollin'"

With the result being:


One could write a class named * as such:

class * {
  def test():String = {

So with that being the case, when I have a class * in the package us.hexcoder and I write:

import us.hexcoder.*

You would be saying that you wish to import a class with the name *. Because of this, Scala needed to use another symbol to indicate a wildcard import. For whatever reason, they decided to use _ as the wildcard symbol.

  • 11
    The question becomes then, why was * chosen as a valid identifier and _ as wildcard? Apr 11, 2013 at 20:01
  • 3
    Even though I have more upvotes, this is the more correct answer. Never heard of * as an identifier before. Apr 11, 2013 at 20:12
  • 1
    @MikeBrown It's also valid in Lisp. Here is an example in Scheme
    – user7007
    Apr 11, 2013 at 21:02
  • 20
    @MikePatridge Almost definitely because Scala defines all of its operators as functions, and allows the developer to define their own operators as such. It doesn't do special-case syntax for operators, and * needed to be included for multiplication. So another less common character needed to be chosen as a reserved character.
    – KChaloux
    Apr 11, 2013 at 23:08
  • 3
    The _ character resembles a blank (as in "fill in the blank"), so whether Scala borrowed it from somewhere else or came up with it themselves, it makes sense to use it as a wildcard. Apr 12, 2013 at 3:11

In functional languages, the _ character is commonly used to say, "I don't care about this parameter" or "anything can go here". Extending that value to namespace imports only makes sense.


In addition to Glenn's answer, import is a valid statement anywhere in Scala and you can import an object or an instance members into scope. As * is obviously a member of many classes, it can not be used as a wildcard for the import statement. So you end up with a string which must not be a valid identifier.

_ comes to mind. The fact that it is used in other places for a different meaning (existential type, function as an instance) is also due to the same issue.


In Scala there are dozens of places where the underscore is used. Using it for wildcard imports is just a logical consequence.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.