Skip to content

Commit c70bd6e

Browse files
committed
Interaction with java translate done
1 parent 7521de3 commit c70bd6e

File tree

1 file changed

+42
-40
lines changed

1 file changed

+42
-40
lines changed

_ru/tutorials/scala-for-java-programmers.md

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,24 @@ languages: ru
8181

8282
Hello, world!
8383

84-
## Interaction with Java
84+
## Взаимодействие с Java
8585

86-
One of Scala's strengths is that it makes it very easy to interact
87-
with Java code. All classes from the `java.lang` package are
88-
imported by default, while others need to be imported explicitly.
86+
Одна из сильных сторон Scala заключается в том, что с ней можно очень
87+
легко взаимодействовать с кодом написаным на Java. Все классы из
88+
пакета `java.lang` импортируются по умолчанию, а другие нужно
89+
импортировать явно.
8990

90-
Let's look at an example that demonstrates this. We want to obtain
91-
and format the current date according to the conventions used in a
92-
specific country, say France. (Other regions such as the
93-
French-speaking part of Switzerland use the same conventions.)
91+
Давайте посмотрим на пример, демонстрирующий это. Мы хотим получить
92+
и отформатировать текущую дату в соответствии с соглашениями,
93+
используемыми в конкретная страной стране, скажем Франции. (Другие
94+
регионы, такие как Франкоязычная часть Швейцарии использует те же
95+
соглашения.)
9496

95-
Java's class libraries define powerful utility classes, such as
96-
`Date` and `DateFormat`. Since Scala interoperates
97-
seamlessly with Java, there is no need to implement equivalent
98-
classes in the Scala class library--we can simply import the classes
99-
of the corresponding Java packages:
97+
Библиотеки классов Java определяют мощные служебные классы, такие как
98+
`Date` и `DateFormat`. Поскольку Scala взаимодействует
99+
без проблем с Java, нет необходимости реализовывать эквивалентые
100+
классы в библиотеке классов Scala - мы можем просто импортировать классы
101+
соответствующих пакетов Java:
100102

101103
import java.util.{Date, Locale}
102104
import java.text.DateFormat._
@@ -109,40 +111,40 @@ of the corresponding Java packages:
109111
}
110112
}
111113

112-
Scala's import statement looks very similar to Java's equivalent,
113-
however, it is more powerful. Multiple classes can be imported from
114-
the same package by enclosing them in curly braces as on the first
115-
line. Another difference is that when importing all the names of a
116-
package or class, one uses the underscore character (`_`) instead
117-
of the asterisk (`*`). That's because the asterisk is a valid
118-
Scala identifier (e.g. method name), as we will see later.
119-
120-
The import statement on the second line therefore imports all members
121-
of the `DateFormat` class. This makes the static method
122-
`getDateInstance` and the static field `LONG` directly
123-
visible.
124-
125-
Inside the `main` method we first create an instance of Java's
126-
`Date` class which by default contains the current date. Next, we
127-
define a date format using the static `getDateInstance` method
128-
that we imported previously. Finally, we print the current date
129-
formatted according to the localized `DateFormat` instance. This
130-
last line shows an interesting property of Scala's syntax. Methods
131-
taking one argument can be used with an infix syntax. That is, the
132-
expression
114+
Оператор импорта в Scala очень похож на эквивалент в Java,
115+
однако он более мощный. Несколько классов можно импортировать из
116+
того же пакета, заключив их в фигурные скобки, как на первой строке.
117+
Другое отличие состоит в том, что при импорте всех имен пакета или
118+
класса, вместо звездочки (`*`) используется символ подчеркивания (`_`).
119+
Это потому, что звездочка - действительный идентификатор Scala
120+
(например, имя метода), как мы увидим позже.
121+
122+
Оператор импорта во второй строке импортирует все элементы класса
123+
`DateFormat`. Это делает статический метод `getDateInstance` и
124+
статическое поле `LONG` напрямую видимыми.
125+
126+
Внутри метода `main` мы сначала создаем экземпляр Java класса `Date`,
127+
который по умолчанию содержит текущую дату. Далее мы определяем формат
128+
даты с помощью статического метода `getDateInstance`, который мы
129+
импортировали ранее. Наконец, печатаем текущую дату отформатированную
130+
в соответствии с локализованным экземпляром `DateFormat`. Эта последняя
131+
строка показывает интересное свойство синтаксиса Scala. Методы
132+
использующие однин аргумент могут использоваться с инфиксным синтаксисом.
133+
Это выражение
133134

134135
df format now
135136

136-
is just another, slightly less verbose way of writing the expression
137+
это просто еще один, менее подробный способ написания выражения
137138

138139
df.format(now)
139140

140-
This might seem like a minor syntactic detail, but it has important
141-
consequences, one of which will be explored in the next section.
141+
Это может показаться незначительной синтаксической деталью, но у
142+
нее есть важные последствия, одно из которых будет исследовано в
143+
следующем разделе.
142144

143-
To conclude this section about integration with Java, it should be
144-
noted that it is also possible to inherit from Java classes and
145-
implement Java interfaces directly in Scala.
145+
В заключение этого раздела об интеграции с Java следует
146+
отметить, что также возможно наследование от классов Java и
147+
реализация интерфейсов Java непосредственно в Scala.
146148

147149
## Everything is an Object
148150

0 commit comments

Comments
 (0)