And you thought the App trait is just a convenient way of creating an executable scala program


Scala App trait with DelayedInit.

Knoldus

Ok,  Let’s start discussion about the App trait uses in our code segment. Here I will try to demonstrate some use cases for the better use of App trait in our scala code. To read more about the App trait you can refer to the documentation here

Let’s go with our daily uses of App trait 🙂

Just want to print something on console:

In the code above, we are inheriting the main method of App. We can do this also to print the same:

Output for the both : Hello Scala!

Now let’s try in advance way:

What do you think is going to be the output of this code block? If you answered
world! you are not correct. Because the output is Welcome to SCALA world!

Nothing special in above code block. I have just overridden the delayedInit method of DelayedInit marker trait. This method is normally never…

View original post 245 more words

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s