@@ -29,26 +29,25 @@ assumed.
29
29
}
30
30
}
31
31
32
- The structure of this program should be familiar to Java programmers:
33
- it consists of one method called ` main ` which takes the command
34
- line arguments, an array of strings, as parameter; the body of this
35
- method consists of a single call to the predefined method ` println `
36
- with the friendly greeting as argument. The ` main ` method does not
37
- return a value. Therefore, its return type is declared as ` Unit ` .
38
-
39
- What is less familiar to Java programmers is the ` object `
40
- declaration containing the ` main ` method. Such a declaration
41
- introduces what is commonly known as a * singleton object* , that
42
- is a class with a single instance. The declaration above thus declares
43
- both a class called ` HelloWorld ` and an instance of that class,
44
- also called ` HelloWorld ` . This instance is created on demand,
45
- the first time it is used.
46
-
47
- The astute reader might have noticed that the ` main ` method is
48
- not declared as ` static ` here. This is because static members
49
- (methods or fields) do not exist in Scala. Rather than defining static
50
- members, the Scala programmer declares these members in singleton
51
- objects.
32
+ Структура этой программы должна быть знакома Java-программистам:
33
+ она состоит из одного метода под названием ` main ` , который принимает
34
+ аргументы командной строки (массив строк в качестве параметра).
35
+ Тело этого метода состоит из единственного вызова предопределенного
36
+ метода ` println ` с дружеским приветствием в качестве аргумента.
37
+ Метод ` main ` не возвращает значение. Поэтому его возвращаемый тип
38
+ объявлен как ` Unit ` .
39
+
40
+ Что менее знакомо программистам на Java, так это ` object ` объявление,
41
+ содержащее метод ` main ` . Такое объявление вводит то, что обычно известно
42
+ как * singleton объект* , то есть класс с единственным экземпляром.
43
+ Таким образом, в приведенном выше объявление как класс под названием
44
+ ` HelloWorld ` , так и экземпляр этого класса, также называется ` HelloWorld ` .
45
+ Этот экземпляр создается по запросу, при первом использовании.
46
+
47
+ Проницательный читатель мог заметить, что ` main ` метод - не объявлен
48
+ здесь как ` static ` . Это потому, что статические члены (методы или поля)
49
+ не существуют в Scala. Вместо определения статических членов,
50
+ программист Scala объявляет их в singleton объекте.
52
51
53
52
### Compiling the example
54
53
0 commit comments