Everybody knows about Java and Scala, but how much interoperability is there between C++ and Scala. Can classes from one be be used by the other, for example?
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.
Rust type system is also extremely powerful and similar to Scala. Rust supports Algebraic data types (ADTs) thanks to its powerful enums and also supports advance pattern matching.
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.
Yes, there is the ability to mix both types of code. It is possible to create an SBT project, put Scala code in src/main/scala and java code in src/main/java in the same project and make it work.
It's not that simple at all. Java and Scala work on the same virtual machine and scala has been designed to work well with java.
C++ generates native code, and even each compiler has its own way to generate that native code. That means that some class compiled with Visual Studio won't interact easily with another class compiled with gcc.
If you need to interact with C++, you need to use some glue with JNI http://en.wikipedia.org/wiki/Java_Native_Interface. I believe it should be straightfoward to use it with scala. You can make interaction somewhat more comfortable using Swig http://www.swig.org/
To make this kind of interoperability even possible, both implementations must compile for the same intermediate language (i.e. Java bytecode, .Net IL, LLVM). Scala.Net and C++/CLI is the closest combination — both produce code for .Net. But even then it's not that simple, as a class in Scala and a class in C++ stand for slightly different things.
Typically, Scala stands for Scala for Java VM, and C++ stands for C++ for native code, so general answer should be “not much more than between any other two randomly picked languages”.
I would've checked out JNAerator. It builds bridges from C/C++/Obj-C header files to Java interfaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With