Constructor in Scala | SAP Blogs [PDF]

Dec 5, 2015 - Note: This blog is written based on Scala 2.11.7. Any codes directly written in the class implementation i

2 downloads 21 Views 1MB Size

Recommend Stories


Manualul inginerului constructor pdf
Courage doesn't always roar. Sometimes courage is the quiet voice at the end of the day saying, "I will

PDF-of-physics-blogs
Don't watch the clock, do what it does. Keep Going. Sam Levenson

PdF Scala Cookbook
And you? When will you begin that long journey into yourself? Rumi

Parallel Programming in Scala
Your big opportunity may be right where you are now. Napoleon Hill

14 Veicolo in Scala
Come let us be friends for once. Let us make life easy on us. Let us be loved ones and lovers. The earth

Scala Sockelleisten Scala Skirts
You often feel tired, not because you've done too much, but because you've done too little of what sparks

SAP 101 SAP Overview [PDF]
Dec 20, 2000 - Internet-Business Framework. (through SAP Products and Services). Value Creation. Integrated end-to-end business process. COLLABORATIVE ...... Workflow. The SAP Business Workflow is a support tool that can be used to optimize the execu

Code Cube Constructor
So many books, so little time. Frank Zappa

READ PDF SAP Plant Maintenance (SAP PM)
What we think, what we become. Buddha

SAP TCodes - The Best Online SAP Transaction ... - SAP-TCodes.org [PDF]
Sep 30, 2016 - This book is based on our knowledge of SAP system, and it is constantly reviewed to avoid errors; well we cannot warrant full correctness of all content. Use the information and content on this book at your own risk. Published by: book

Idea Transcript


Home / Community / Blogs

Constructor in Scala December 5, 2015

| 59 Views |

Jerry Wang more by this author

Retagging required app | constructor | delayedinit | initcode | jerry wang s blog | listbuffer | scala

share 0



share 0



tweet



share 0



Follow

Note: This blog is written based on Scala 2.11.7. Any codes directly written in the class implementation in Scala will be considered as constructor code, for example below. When an instance of test is created, the constructor is called. Nothing new compared with Java and ABAP so far.

However, if we modify class test a little bit, to make it extend from App, then after an instance is created, constructor code is not called at all. Why?

Check the bytecode generated after this sample scala program is compiled and we can find the following useful points:

1. In the constructor of test class, there is no code to print out Hello World, which explain the reason why we see nothing when a new instance of test is created. 2. Instead, the Hello World string will be printed out in another public method of class: delayedEndpoint$blog$test$1(). It will be called by an inner class delayedInit$body, method apply(). The method name here is interesting since in Scala we can also explicitly call apply method on any function to execute it. 3. The code in test constructor simply calls the function delayedInit provided in App implementation: (a) Each App instance has a internal ListBuffer which has a line type of a function with no input argument and no return value. The delayedInit function simply accepts a function with such type and append it to the ListBuffer and that’s all.

(b) Back to our example, our constructor code contained in Java method delayedEndpoint$blog$test$1(), which is actually the body of function delayedInit$body, which is appended to the ListBuffer via the code in Test constructor code: delayedInit(new delayedInit.body()); }

In the implementation of App, we can also find there is one method main, where the ListBuffer is looped and each function within it is executed one by one. This gives us a hint: our constructor will be executed, once we explicitly call main method on the created app instance. Let’s verify it.

It works as expected. We can also find in the debugger that in the runtime, there is indeed one entry in ListBuffer, which contains our Hello World printing code.

You can also find how those compiled Java class methods are called in the runtime in the debugger.

Alert Moderator

Be the first to leave a comment You must be Logged on to comment or reply to a post.

Share & Follow















Privacy

Terms of Use

Legal Disclosure

Copyright

Trademark

Sitemap

Newsletter

Smile Life

When life gives you a hundred reasons to cry, show life that you have a thousand reasons to smile

Get in touch

© Copyright 2015 - 2024 PDFFOX.COM - All rights reserved.