Scala as the new Java?

前端 未结 8 604
梦谈多话
梦谈多话 2021-02-01 02:51

I just started exploring Scala in my free time.

I have to say that so far I\'m very impressed. Scala sits on top of the JVM, seamlessly integrates with existing Java co

相关标签:
8条回答
  • 2021-02-01 03:37

    It consistently breaks backwards compatibilty. Community size is small. IDE support isn't there yet.

    Otherwise its fine.
    It is just a young language, it will get there eventually. Great for hobbyists, not ready for enterprise.

    0 讨论(0)
  • 2021-02-01 03:42

    I'll tell you my little personal experience, and how I found that it wasn't so easy to integrate Scala with existing Java libraries:

    I wanted to get started with something easy, and as I thought that Scala was very well suited for scientific computation I wanted to do a little wrapper around JAMA (Java Matrix library)... My initial approach was to extend the Matrix type with a Scala class and then overload the arithmetic operators and call the Java native methods, but:

    • The Matrix class doesn't provide a default constructor (without arguments)
    • The Scala class needs one primary constructor
    • I thought one good primary constructor could be the one accepting an Array[Array[Double]] (first thing that sucks, that syntax is much more verbose and hard to read than Double[][])
    • As far as I know by reading the manuals, the parameters of the primary constructor are also implicitly fields of the class, so I would end with one Array[Array[Double]] in the Scala subclass and another double[][] in the Java superclass, which is pretty redundant.

    I think I could have used an empty primary constructor that initialized the superclass with some default values (for example, a [[0]]), or just make an adapter class that used the Jama.Matrix as a delegate, but if a language is supposed to be elegant and seamless integrated with another, that kind of things shouldn't happen.

    Those are my two cents.

    0 讨论(0)
提交回复
热议问题