6

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?

5
  • 8
    Look at this article: What features of Java have been dropped in Scala? Commented Nov 1, 2012 at 18:55
  • @RobertHarvey That should be posted as an answer :) Though the author was a self-admitted newbie when he wrote it, so there might be some omissions and mistakes (I'm a Scala newbie myself, so I can't tell).
    – Andres F.
    Commented Nov 1, 2012 at 20:54
  • @Robert Harvey: Thanks for the link. With the term 'major features' I mean features that can radically influence the way in which you design a program. For example, I consider multiple inheritance a major feature, and the ++ (increment operator) a minor feature. My feeling is that, apart from some minor aspects, Scala is a super-set of Java, i.e. I can take a Java program and port to to Scala by rewriting it almost line-by-line (if I want to do so, even though Scala might offer better constructs). This is however a newbie feeling: I am a beginner with Scala.
    – Giorgio
    Commented Nov 2, 2012 at 10:22
  • 1
    I have no problem to delete this question if someone finds it does not belong in this site or if it is not formulated properly but I would appreciate whoever down-voted it to write a short comment explaining what is wrong with it. Thanks.
    – Giorgio
    Commented Nov 2, 2012 at 14:58
  • @Robert Harvey: The link provides really good information. I have a feeling that I can use this document as a starting point for porting Java code to Scala. If you post it as an answer I will up-vote it.
    – Giorgio
    Commented Nov 2, 2012 at 15:13

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.