Scala – Can Scala Be Considered a Functional Superset of Java?

javaprogramming-languagesscala

Apart from the differences in syntax, can Scala be considered a superset of Java that adds the functional paradigm to the object-oriented paradigm?

Or are there any major features in Java for which there is no direct Scala equivalent?
With major features I mean program constructs that would force me to heavily rewrite / restructure my code, e.g., if I had to port a Java program to Scala. Or can I expect that, given a Java program, I can port it to Scala almost line-by-line?

Best Answer

I think it's not too much of an over-simplification to say, "Yes." Look at lambdas in Java 8 - they work almost exactly like they work in Scala now, but retrofitted to be backward-compatible with the way Java works now.

All the collections and most of the APIs in Scala are immutable by default which is a nice plus. I wish they would port that back to Java. The Java APIs are very inconsistent in regard to immutability. Make sure to check out Robert Harvey's link in the comments under the original question - it offers a much more detailed and nuanced answer to this question.

Related Topic