Moment For Technology

Scala - Abstraction, inheritance, polymorphism

Scala's abstract keywords are abstract, just like Java's, and abstract classes cannot be instantiated. In addition to classes that can be defined as abstract, the properties and methods of a class can also be abstract. From the following example, you can see that there is no difference between abstract class definitions in Java. Right

Scala - Process control

When using IF for process control, it includes single branch, double branch, and multiple branch. For example, Java is written like this. {code... } Scala is similar: {code... If you don't specify the type of the variable, the compiler will automatically infer that else () is the default if no else is written, so x1 will print () and if it is a block expression, the return value will be the last line {code.....

Scala - Definitions of variables, blocks, methods, functions, and data types

In Java, we define variables as follows: {code... } In Scala, we define variables like this: {code... Scala can also specify the type of a variable without specifying it. Scala will infer the type of a variable based on the type assigned to it. So the following statement will print int...

Scala - Definitions of classes

In Java, we define a class like this: {code... } the call looks like this: {code... } In Scala, the definition of a class is as follows. Since all variables in Scala are defined with an initial value, we can define the underscore here to indicate that it is empty. {code... } the call looks like this: {code... } it looks like we are calling the properties of the object directly, but Scala hides the setter and getter, I...

Scala - Implicit Conversion

Sometimes when we look at Scala code, we see that there is no type or function of the class, or even without the class, not only does the compiler report no errors, but the program runs just fine. In fact, we use Scala's implicit conversion.

Scala - Companion object

In the previous article, you might also have noticed that the main method doesn't have a static keyword like the Java keyword, and that the class that runs the main method defines an Object. A class defined by Object can have the same name as a class defined by Class. Class ScalaObject and Object ScalaObject, we can say Object ScalaObject is a companion object to Class ScalaObject, Class ScalaObject is a companion class to Object ScalaObject...

Scala - sequence

Define the List, including apply, :: Nil, and ::: to define the List. Nil is an empty collection, and :: is a new list made from the head element and tail list, and this is evaluated from the end, so the following is evaluated first with respect to 3::Nil, then 2::(3 ::Nil), and finally 1:: ::Nil). If head is a List, the first element is still a List, so use ::: to form a new List. See...

Scala - Pattern Matching

Let's take a string as an example. The keyword is match, case followed by = >; To separate the matched pattern from the matched code. Case is each branch, and if the match is successful, the corresponding code block is executed, which can be used without curly braces. If neither match, then the block of code in case _ is executed, relative to the Java default.

Scala - 特质Trait

In Scala, there is a concept that looks both like a Java interface and like a Java abstract class called a Trait. We can use it as an interface, similar to a Java interface, or we can use it as an abstract class, similar to a Java abstract class. But either in an interface or abstract way, the extends keyword is used. Interface mode:

Scala collection -

Set is divided into mutable Set and immutable Set. Set {code... } mutable.Set loop, union, difference, handoff, same as above, here do not do the labile {code... }

About (Moment For Technology) is a global community with thousands techies from across the global hang out!Passionate technologists, be it gadget freaks, tech enthusiasts, coders, technopreneurs, or CIOs, you would find them all here.