Declare a variable with no initialization

Published on Author admin5 Comments

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 leastFavoriteDonut of type String, but you won’t initialize it just yet.

scala> var String = _;

msg: String = null;

scala> msg = "NPN Training";

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

5 Responses to Declare a variable with no initialization

  1. Very nice post. I just stumbled upon your weblog and wanted to say that I have truly enjoyed browsing your blog posts. In any case I will be subscribing to your feed and I hope you write again very soon!

Leave a Reply

Your email address will not be published. Required fields are marked *