Java有闭包后的Scala优势 [英] Scala advantages after Java having closures

查看:123
本文介绍了Java有闭包后的Scala优势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有人可以详细说明任何优点吗?

解决方案

除了闭包(Java没有显示所有接近),这里有一个从Java中缺少的Scala中的功能列表。我将在这里省略图书并专注于语言本身的功能。




  • 隐含参数/转换次数

  • 模式匹配,案例类

  • 键入引用(某些)

  • 高级类型(对类型构造函数的抽象)

  • Monadic / code> comprehensions

  • 差异注释

  • 与行为接口

  • 命名参数

  • 统一的方法和运算符(方法可以用作中缀运算符,运算符可以重载,因为它们只是方法)

  • 层次;没有原始类型

  • 属性而不是getter和setter

  • 抽象值

  • val 很容易声明为 var s)


  • 一些尾调用递归优化

  • 抽象类型

  • 键入别名

  • 自身类型

  • 路径依赖类型

  • 结构类型

  • 输入
  • 重命名导入

  • 第一类模块(对象)

  • 第一类包

  • 已认证的泛型(清单

  • 分隔的延续



这些构建模块支持的一些很酷的二级结构:



$ b最后,我将提到Scala有一个REPL(read-evaluate-print-loop) - 并不是语言本身的一个特征,但它是非常好的!


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 (vals are as easy to declare as vars)
  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆