开发人员应该学习 Java 生态系统和语言的哪些部分才能充分利用 Scala? [英] What parts of the Java ecosystem and language should a developer learn to get the most out of Scala?

查看:36
本文介绍了开发人员应该学习 Java 生态系统和语言的哪些部分才能充分利用 Scala?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多用于学习 Scala 的可用资源都假设有一些 Java 背景.对于没有 Java 背景而尝试学习 Scala 的人来说,这可能具有挑战性.

Many of the available resources for learning Scala assume some background in Java. This can prove challenging for someone who is trying to learn Scala with no Java background.

新的 Scala 开发人员在学习该语言时应该了解哪些 Java 主义?

What are some Java-isms a new Scala developer should know about as they learn the language?

例如,了解 CLASSPATH 是什么、java 命令行选项是什么等很有用...

For example, it's useful to know what a CLASSPATH is, what the java command line options are, etc...

推荐答案

这真是个好问题!我从没想过人们学习 Java 只是为了更轻松地学习 Scala...

That's a really great question! I've never thought about people learning Java just so they have it easier to learn Scala...

除了 for 循环等所有基础知识外,学习 Java 泛型真的很有帮助.Scala 等价物比 Java 泛型更有效(也更难理解).您可能想尝试找出 Java 泛型的限制在哪里,然后在哪些情况下可以使用 Scala 的类型构造函数来克服这些限制.在更基础的层面上,了解为什么需要泛型以及 Java 如何成为强类型语言非常重要.

Apart from all the basics like for loops and such, learning Java Generics can be really helpful. The Scala equivalent is much more potent (and much harder to understand) than Java Generics. You might want to try to figure out where the limits of Java Generics are, and then in which cases Scala's type constructors can be used to overcome those limitations. At the more basic level, it is important to know why Generics are necessary, and how Java is a strongly typed language.

Java 允许您为一个类使用多个构造函数.当您学习 Scala 时,这些知识将毫无用处,因为 Scala 有另一种方式允许您提供多种方法来创建类的实例.所以,您宁愿不深入了解这个 Java 概念.

Java allows you to have multiple constructors for one class. This knowledge will be of no use when you learn Scala, because Scala has another way that allows you to offer several methods to create instances of a class. So, you'd rather not have a deep look into this Java concept.

以下是一些在 Java 和 Scala 之间差异很大的概念.所以,如果你学习了 Java 概念,然后想学习 Scala 中的等价物,你应该意识到 Scala 等价物与 Java 版本有很大不同,以至于典型的 Java 开发人员很难适应 Scala 方式的思考.不过,首先习惯 Java 方式通常会有所帮助,因为它通常更简单、更容易学习.我个人更喜欢将 Java 视为入门课程,而 Scala 是专业版.

Here are some concepts that differ very strongly between Java and Scala. So, if you learn the Java concepts and then later on want to learn the equivalent in Scala, you should be aware that the Scala equivalent differs so greatly from the Java version that a typical Java developer will have some difficulty to adapt to the Scala way of thinking. Still, it usually helps to first get used to the Java way, because it is usually simpler and easier to learn. I personally prefer to think of Java as the introductory course, and Scala is the pro version.

  • Java 可变集合概念与 Scala 可变/不可变区分
  • static 方法(Java)与单例对象(Scala)
  • for 循环
  • Java return 语句与 Scala 函数式风格(每个表达式都返回一个值")
  • Java 将 null 用于无值"与 Scala 更显式的 Option 类型
  • 进口
  • Java 的 switch 与 Scala 的 match
  • Java mutable collection concept vs. Scala mutable/immutable differentiation
  • static methods (Java) vs. singleton objects (Scala)
  • for loops
  • Java return statement vs. Scala functional style ("every expression returns a value")
  • Java's use of null for "no value" vs. Scala's more explicit Option type
  • imports
  • Java's switch vs. Scala's match

这里列出了您可能会从 Java 标准库中使用的内容,即使您是在 Scala 中开发的:

And here is a list of stuff that you will probably use from the Java standard library, even if you develop in Scala:

  • IO
  • GUI(Scala 有一个 Swing 的包装器,但是嘿)
  • 网址、URI、文件
  • 日期
  • 计时器

最后,Scala 的一些特性在 Java 或 Java 标准库中没有直接的等价物:

And finally, some of Scala's features that have no direct equivalent in Java or the Java standard library:

  • 运算符重载
  • 隐式和隐式转换
  • 多参数列表/柯里化
  • 匿名函数/作为值的函数
  • 演员
  • Scala 模式匹配(非常棒)
  • 特点
  • 类型推断
  • 用于理解
  • 很棒的集合操作,例如 foldmap

当然,所有的清单都是不完整的.这只是我对重要的看法.我希望它有所帮助.

Of course, all the lists are incomplete. That's just my view on what is important. I hope it helps.

顺便说一句:您绝对应该了解类路径和其他 JVM 基础知识.

And, by the way: You should definitely know about the class path and other JVM basics.

这篇关于开发人员应该学习 Java 生态系统和语言的哪些部分才能充分利用 Scala?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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