2

I stumble upon scala code like this:

var folderName: String = _

What does the = _ do? And is there a proper name for this language feature?

Yuchen
  • 30,852
  • 26
  • 164
  • 234
  • Click [here](https://stackoverflow.com/questions/8000903/what-are-all-the-uses-of-an-underscore-in-scala) and search for "default". – jwvh Apr 16 '18 at 02:04

1 Answers1

4

= _ is used to set the default value when initialising a variable.

  1. var s: String = _ will set s equal to null.
  2. var i: Int = _ will set i equal to 0.
Matt Doyle
  • 867
  • 8
  • 12