September 2015
Intermediate to advanced
250 pages
6h 40m
English
You can extend a Java class from a Scala class, and vice versa. For the most part, this should just work. As discussed earlier, if your methods accept function values as parameters, you’ll have trouble overriding them. Exceptions are also a problem.
Scala doesn’t have the throws clause. In Scala you can throw any exception from any method without having to explicitly declare that as part of the method signature. However, if you override such a method in Java, you’ll run into trouble when you try to throw an exception. Let’s look at an example. Suppose we have a Bird class defined in Scala:
| | abstract class Bird { |
| | def fly() |
| | //... |
| | } |
We also have another class, Ostrich:
| Intermixing/Ostrich.scala | |
| | class Ostrich ... |
Read now
Unlock full access