Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What features of Scala cannot be translated to Java?

Tags:

java

idioms

scala

The Scala compiler compiles direct to Java byte code (or .NET CIL). Some of the features of Scala could be re-done in Java straightforwardly (e.g. simple for comprehensions, classes, translating anonymous/inner functionc etc). What are the features that cannot be translated that way?

That is presumably mostly of academic interest. More usefully, perhaps, what are the key features or idioms of Scala that YOU use that cannot be easily represented in Java?

Are there any the other way about? Things that can be done straightforwardly in Java that have no straightforward equivalent in Scala? Idioms in Java that don't translate?

like image 269
The Archetypal Paul Avatar asked Nov 29 '10 14:11

The Archetypal Paul


People also ask

Is Scala fully interoperable with Java?

Scala source code compiles to Java bytecode, so it can execute on any JVM. It also provides complete interoperability with Java, and hence, we can reference Java from Scala and vice versa with ease.

How is Scala different from Java?

Scala is a statically typed programming language, whereas Java is a multi-platform, network-centric programming language. Scala uses an actor model for supporting modern concurrency, whereas Java uses the conventional thread-based model for concurrency.

What are the advantages of Scala over Java?

The Advantages of ScalaScala has an exact syntax, eliminating boilerplate code. Programs written in Scala require less code than similar programs written in Java. It is both an object-oriented language and a functional language. This combination makes Scala the right choice for web development.

Why is Scala compatible with Java?

Scala is a statically typed language that is based on Java. Thus, anyone who's well-versed with Java's syntax will find it pretty easy to learn Scala.


1 Answers

Traits are one thing that does not have an equivalent. Traits are Interfaces with code in them. You can copy the code to all classes that have a trait mixed in, but that is not the same thing.

Also I believe scala type system is more complete. While it will eventually map to the JVM types (actually suffer erasure). You can express some things in the Scala type system that may not be possible in Java (like variances).

like image 97
Thomas Avatar answered Oct 03 '22 21:10

Thomas