Getting started with Scala-02 Basics--Method

Source: Internet
Author: User

First, under the SRC under main under Scala create a package for org.scala.base



Create a Scala class name of HELLOWORLD.SCLA



Because the main method is to be in the object, we create an object name called HelloWorld and add the main method and print a line of content


Next we add a method to the object: Printlnhello;



Ps:

1. The value of the last line of the function body is the return value of the entire function.

2. The Declaration of type is at the back of a variable or function or class

Another way to define a method:



When the method or function is parameterless, we can omit the parentheses when calling



Next we define an anonymous function and call


The Keli of Scala's function programming, this feature allows the function to be defined with two parentheses:


Scala Variable parameter usage:


Scala method Default Parameters:



Getting started with Scala-02 Basics--Method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.