Java有闭包后的Scala优势 [英] Scala advantages after Java having closures
问题描述
有人可以详细说明任何优点吗?
除了闭包(Java没有显示所有接近),这里有一个从Java中缺少的Scala中的功能列表。我将在这里省略图书并专注于语言本身的功能。
- 隐含参数/转换次数
- 模式匹配,案例类
- 键入引用(某些)
- 高级类型(对类型构造函数的抽象)
- Monadic
/ code> comprehensions
- 差异注释
- 与行为接口
- 命名参数
- 统一的方法和运算符(方法可以用作中缀运算符,运算符可以重载,因为它们只是方法)
- 层次;没有原始类型
- 属性而不是getter和setter
- 抽象值
-
val
很容易声明为var
s) - 一些尾调用递归优化
- 抽象类型
- 键入别名
- 自身类型
- 路径依赖类型
- 结构类型
- 输入
- 重命名导入
- 第一类包
- 已认证的泛型(清单)
- 分隔的延续
这些构建模块支持的一些很酷的二级结构:
- 输入类(通过隐式参数和更高类型的类型)
- Pimp我的图书馆模式(通过隐式转换)
- 内部DSL(通过操作符重载和中缀方法)
- 解析器组合器(由高阶函数启用,并通过中缀方法制作)
- 生成器,协同程序,
- 依赖注入框架的过时(通过 http://jonasboner.com/2008/10/06/real-world-scala-dependency-injection-di.html\">烘焙图案)
With closures being added to Java, what is Scala's advantage over Java as a language choice?
Can someone elaborate on any advantages?
Apart from closures (which Java doesn't appear all that close to having), here's a list of features in Scala that are missing from Java. I'll omit libraries here and concentrate on the features of the language itself. This is not comprehensive by any means, but I think it contains the big ticket items.
- Implicit parameters / conversions
- Pattern matching, case classes
- Type inferencing (some)
- Higher-kinded types (abstraction over type constructors)
- Monadic
for
comprehensions - Variance annotations
- Interfaces with behavior (traits)
- Default and named arguments
- Unified methods and operators (methods can be used as infix operators, operators can be overloaded because they're just methods)
- Unified type hierarchy; no primitive types
- Properties rather than getters and setters
- Abstract values
- First-class immutable references (
val
s are as easy to declare asvar
s) - By-name (lazy) terms (maybe Java closures would make this reasonably easy to express)
- Some tail-call recursion optimization
- Abstract types
- Type aliasing
- Self types
- Path-dependent types
- Structural types
- Type ascription, as distinguished from type casting
- Renaming imports
- First-class modules (objects)
- First-class packages
- Reified generics (manifests)
- Delimited continuations
Some cool secondary constructs that these building blocks enable:
- Type classes (via implicit parameters and higher-kinded types)
- The "Pimp My Library" pattern (via implicit conversions)
- Internal DSLs (via operator overloading and infix methods)
- Parser combinators (enabled by higher-order functions and made pretty by infix methods)
- Generators, coroutines, custom control structures (via delimited continuations)
- Type-level programming (via higher-kinded and abstract types)
- Obsolescence of dependency injection frameworks (via the Cake Pattern)
Lastly, I'll mention that Scala has a REPL (read-evaluate-print-loop)--not really a feature of the language itself, but it's very nice to have!
这篇关于Java有闭包后的Scala优势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!