Declare a variable with no initialization

Sometimes you may not know the value of your variable immediately. You can only assign your variable’s value at some later point in time during the execution of your application.

Let’s assume that you need to declare a variable called msg of type String, but you won’t initialize it just yet.

scala> var msg:String = _;

msg: String = null;

scala> msg = "NPN Training";

  • We’ve use the wildcard operator _ when defining our variable.