Current location - Training Enrollment Network - Mathematics courses - Error running scala in IDEA.
Error running scala in IDEA.
Scala is a modern multi-paradigm programming language, which aims to express common programming patterns in a concise, elegant and type-safe way. It smoothly integrates the characteristics of object-oriented language and functional language. Scala is object-oriented: Scala is a purely object-oriented language, and all values are objects in a sense. The types and behaviors of objects are described by classes and characteristics. The abstraction of classes can be extended by subclassing and flexible combination mechanism based on mixin, which can be used as a simple alternative to multiple inheritance. Scala is functional: Scala is also a functional language. In a sense, all functions are numerical. Scala provides a lightweight syntax for defining anonymous functions, supports high-order functions, allows function nesting, and supports local currying. Scala's case class and its built-in pattern matching model supporting algebraic types are used in many functional programming languages. Scala is statically typed: Scala is equipped with an expressible type system, and this abstract concept is used in a safe and consistent way. Scala is extensible: Scala's design recognizes the fact that domain-specific application development usually requires domain-specific language extensions. Scala provides a unique language combination mechanism, which makes it easier to add new language structures in the form of class libraries: the combination of the two can easily define new sentences without extending grammar or using metaprogramming tools such as macros. Any closure that can be used as an infix or suffix operator is automatically constructed according to the expected type (target type). Scala can work with Java and. NET: Scala's design has a good interaction with popular programming environments, such as Java2 runtime environment (JRE) and. Remember the. NET Framework (CLR). Especially mainstream object-oriented languages, such as Java and C#. Scala has the same compilation model as Java and C# (independent compilation and dynamic loading of classes), allowing access to thousands of high-quality class libraries. For some developers, these incentives are enough to attract them to leave Java and enter the world of Scala. But for other developers, they have not brought benefits to the daily programming activities currently performed in the Java world. In a blog post called Scala: The Essence of Ruby and Java, Ian said that you should not choose between Java and Scala. On the contrary, choosing a mixture of Java and Scala is another choice compared with choosing other languages such as Ruby: many developers love Ruby, but they can't get enough satisfaction from it. It is probably one of the most aggressive languages, because Java appeared first. People always refer to Ruby's flexible and extensible syntax, closures and other features, and how concise and expressive its code is. For example, you can create a map with simple syntax (Ruby calls it "hashes", although hashtable is only one possible implementation of map), such as: numberMap = {"one" => 1, "two" = >; 2, "three" = >; 3} The equivalent statement of 3}Java is quite lengthy: map number map = new hashmap (); numberMap.put("one ", 1); numberMap.put("two ",2); NumberMap.put ("three", 3); What about Scala? Let's take a look at the example of map in Scala: varnumbermap = map ("one"-> 1, "two"->; 2, "three"->; 3) You will notice that it looks very similar to the equivalent Ruby code, but there are some important differences. In particular, like Java, the Scala compiler knows that numberMap uses String as the key and Integer as the value. Unlike Java, you don't have to tell it, it can understand this by itself! This is called "type reasoning". This means that if you try to add a new key-value pair to numberMap, but use Integer as the key and String as the value, when you try to compile it, Scala will immediately report an error (or your IDE will immediately warn you). With Ruby, only when you run the software and try to retrieve keys and values from the map will you get an integer and a string instead of the expected string and integer, which will lead to an error. It is difficult to emphasize how much time type checking saves at compile time, but it eliminates the errors that all classes will make when they execute. Scala brings you this benefit, and the code is not cumbersome. In order to further demonstrate the reduction of code in a small example, TedNeward studied the differences between developing the same class with Java, C#, VirualBasic, Ruby and Scala. Please refer to its blog post Scalapt2: Short. Ian goes on to point out that Scala has a series of other good Ruby features (which Java lacks), including closures and plastic syntax that are very suitable for "domain-specific languages". It has all these characteristics and combines the advantages of static type. DavidMacIver is very serious in his blog post. Why did he choose Scala? He shared his views on object-oriented programming, module-oriented programming, static typing and function programming, as well as the self-evident features of his favorite language. He added: Scala is far from perfect. It has some grammatical defects, some problems brought by Java, a moderately problematic compiler and a bunch of trivial features and edgecase that you can't remember. However, I found that these questions have no consequences except annoying you. If you just want to sit down and write good code, the core of the language is powerful and very useful. In order to provide a balanced point of view, David continued to discuss why Scala was not chosen in his blog post, in which he expounded some edgecase. Finally, David has the following comments: All in all, I found that these just added some trouble. It is still my favorite JVM language, but your opinion will depend on how you shelve things that may be more important to you and need priority. In order to show that Scala is a mature language, the book ProgramminginScala will be published soon. If you can't wait, there is a preprint of this book in PDF format on Artima's website.