This article will explain the ubiquitous case class and pattern matching in Scala, why put it together, because it is generally used in conjunction with pattern matching, and is used to never want to write Java code after this set of combinations, use Les s code to show more! Case Class
Case class refers to the word keyword in front of class, and here is an example:
Abstract class Animal case
class Dog (name:string) extends Animal case
class Cat (name
ObjectiveFirst of all, we want to emphasize one important thing at the outset: Scala's pattern matching occurs but is not limited to the match case statement block, which is one of the key factors that Scala pattern matching is important and useful! We will discuss this in detail in the latter part of the article.Types of pattern matchingThere are several types of pattern matching in Scala:
Wildcar
Knowledge Points: 1. Simple class and no parameter method class Counter { private// must initialize field // method default is public def Current () = value}In Scala, a class does not declare that a Public,scala source file can contain multiple classes, all of which have common visibility. New // or New Counter () mycounter.increment () println (Mycounter.current ())Call the no parameter method, you c
1. Pattern matching is much more powerful than switch case in Java, in addition to matching values, types, collections, and so on, the most common case class matches, and Master.scala has a large number of pattern matches.Case "_" means an experience that does not satisfy all of the above scenarios, for example:def bigdata (data:string) {Data match{Case "Spack" =>PRINTLN ("WOW!!!")Case "Hadoop" =>println ("OK")Case _=>println ("sorry")}}Bigdata ("spack")//WOW!!!You can add conditional judgment t
in Scala. Apply method has different meanings, and for a function This method means invoking the function itself, the following excerpt from programming in Scala, 3rd Edition
Every function value is a instance of some class that extends one of the several functionn traits in the package Scala, such as F Unction0 for functions with no parameters, Function
Refer to Scala Installation: http://www.lupaworld.com/thread-970271-1-1.html
The following command installs the default Scala version
sudo apt-get install Scala
If you want to install a specific version, follow these steps:
1) Download Scala compression packwget http://downloads.typesafe.com
All the operators in Scala are calls to methods, for example: 1+2, equivalent to (1). + (2)0 to 5, equivalent to (0). to (5), X (1) = "Scala", equivalent to (x). Update (1, "Scala"), X (1) is equivalent to (x). Apply (1)
Scala separates static members by defining the associated object, similar to the static keyword
Java™ developers can use objects as a starting point for understanding Scala. This is the second phase of the Scala Guide series for Java developers, and the author Ted Neward follows the basic premise of evaluating a language: the power of a language can be measured directly by its ability to integrate new functionality, which in this article refers to support for complex numbers. Following this article, y
1.Intellij Idea Configuring the Scala development environment
Fix plugin Scala is not installed:no route to hostPlugin Scala wasn't installed:connect timed outPlugin Scala is not installed:cannot download ' http://plugins.jetbrains.com/files/1347/27110/ Scala-intellij-bin-2
Label:Debugging Java code in the Linux/C + + code is required through GDB. Then you need to use the Jdb tool. The use of jdb on the internet can be found in the corresponding article, but the Scala debugging is relatively small. In fact, the general process of debugging is the same, just need to pay attention to some of the details of the place to be. Here's a quick explanation. Here are the questions about Scala
Reprinted from Http://www.tuicool.com/articles/jYzuAv and http://www.importnew.com/1537.htmlIn a keynote speech that I collaborated with Martin Fowler, he made an insightful point:The legacy of Java will be the platform, not the programming language.The original engineers of Java technology made a wise decision to separate the programming language from the runtime environment, which ultimately enabled more than 200 languages to run on the Java platform. This architecture is critical to the long-
01. Introduction and installation of Scala 1.1 Scala introductionScala is the Java language scripting, the feature is that the Java language is not scripted to use the script, so that it has a simple script language, WYSIWYG features, and high programming efficiency, fast implementation and other characteristics. In the big Data world, the famous frameworks for Spark and Kafka are written in the
Functional Object
Advantages and disadvantages of immutable object
Adv 1. Immutable objects are more likely to be inferred because they do not change values over time.
Adv 2. immutable objects can be automatically transmitted without changes. To transfer a mutable object, you must first back up the mutable object to prevent modification to the object state in other processes.
Adv 3. The thread cannot change the state of an immutable object (corruption, corruption). It is destined to be thread-sa
1.scala InterpreterThe installation process is similar to a JDK installation, you need to install the JDK first, and then download and install Scala to configure the PATH environment variable.2. Run cmd in the win environment using WIN+R, bring up the command window, execute the callout command①scala Support TAB Command Auto-completion②
As we all know, Scala is a functional programming language of the Geek type, and the features supported include:
The function has a "class citizen" status;
Support for anonymous functions (volume of function numbers)
Supports higher order functions
Support closures
Partial application functions
Currying
The first point to note is that there are two forms of methods and function objects in
To simplify the installation of Hadoop and Spark, write this today.First of all, to see how many machines on hand, to install pseudo-distributed hadoop+spark or fully distributed, here are recorded separately.1. Pseudo-Distributed installationPseudo-distributed Hadoop is the Namenode,secondarynamenode,datanode and so on a machine to execute, spark the same, generally used in the development environment.1.1 Preparatory workSystem Preparation: A Ubuntu16.04 machine, preferably connected to the Int
PS: The contents of this article are mainly from the notes of Brother Ningshi.1, download scala.tgz. Note. msi is a program under Windows and cannot be opened in Linux.Http://www.scala-lang.org/download/2.11.6.html inside can be downloaded. Down, you can see the tgz format.2. Create and copy to the Usr/scala folder.In Linux Desktop Edition can not knock command. Open the computer directly, it contains all the folders under Linux.3, unzip the folder.Wh
OverviewTo put it simply, implicit conversions are: When the Scala compiler does type matching, if no suitable candidate is found, implicit conversions provides another way to tell the compiler how to convert the current type to the expected type. This article source: http://blog.csdn.net/bluishglc/article/details/50866314 prohibited any form of reprint, or will entrust CSDN official maintenance rights!There are four common usage scenarios for implici
map4. Sorted MappingsAn immutable tree map is obtained as follows: Val scores4 = Scala.collection.immutable.SortedMap ("Alice", "Bob", 7, "Cindy", 9)For variable tree mappings, the closest option is to use Java's treemap.If all keys are accessed in the order in which they are inserted, Linkedhashmap is used. Val months = Scala.collection.mutable.LinkedHashMap ("January", 1, "February", "2", "March", 3, "April", 4, 5,...)5. Interoperability with JavaTranslating Java mappings into a
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.