On Performance and Java Interoperability: Clojure vs. Scala

前端 未结 8 686
滥情空心
滥情空心 2021-01-30 01:47

I have already read various accounts of Clojure vs. Scala and while I realize that both have their place. There are a few considerations that I haven\'t acquired a complete exp

相关标签:
8条回答
  • 2021-01-30 02:05

    The November 2010 issue of PragPub discusses Clojure-Java interoperability. Calling Java methods is straightforward, but extending Java classes/interfaces is quite different.

    Scala on the other hand is much closer to Java. Scala-Java interoperability is elaborated at http://www.codecommit.com/blog/java/interop-between-java-and-scala

    Calling Java code and extending Java classes/interfaces works the same way as calling Scala code. Some pain points might be some edge cases of dealing with Java's generics, because Scala's type system is much stronger than Java's. Creating getters and setters following the Java Bean convention requires an annotation.

    Calling Scala from Java is most of the time straightforward, but for example Scala's companion objects requires knowing how they are compiled to bytecode. Also using traits with non-abstract methods from Java should be complicated, and calling methods with special characters would require knowing how they are encoded in the bytecode.

    0 讨论(0)
  • 2021-01-30 02:13

    It's now (as of May 2010) worth loking at the latest 1.2 branch of Clojure - this includes a lot of additional support for primitive types and static typing (through various type hints and protocols).

    My understanding is that you can use these features when you need it to get speed equivalent to writing exactly the same code in pure Java.

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