Flix is Java Virtual Machine (JVM)-based programming language, hence:
- Flix programs compile to efficient JVM bytecode.
- Flix programs run on any Java Virtual Machine1.
- Flix programs can call Java code.
Flix supports most Java features necessary for interoperability:
- Creating objects from existing classes
- Calling methods on classes and objects
- Reading and writing fields on objects
- Anonymous extension of classes and interfaces
- Nested and inner classes
Thus Flix programs can reuse Java Class Library and have access to the Java ecosystem.
Flix and Java share the same base types, in particular:
|Flix Type||Java Type|
In Flix primitive types are always unboxed.
Hence, to call a Java method that expects a
if you have a Flix
Int32, it must be boxed by calling
Design Note: Unlike other programming languages that target the JVM, Flix does not aim to embed the Java type system within Flix. Instead, Flix sacrifices some convenience to stay true to its design goals. In particular, the Flix type system does not support sub-typing. Consequently, unlike in Java, a sub-type cannot be used where its super-type is expected. For example,
java.lang.Stringis incompatible with
java.lang.Object. Fortunately, this limitation can be overcome by using upcasts.
Flix currently targets Java 11. Once Project Loom is released, we will target that version.