We can import the constructor of a Java class as a Flix function and use it to construct new objects.
import new java.io.File(String): ##java.io.File \ IO as newFile; newFile("HelloWorld.txt")
Here we import the constructor of the
class and give it the local name
newFile function takes a string argument and
returns a fresh Java
Constructing a fresh object is impure, hence
is marked as having the
When we import a constructor, we must specify the types of its formal parameters. This is required because Java supports constructor overloading (i.e. a class may have multiple constructors only distinguished by their formal parameters.)
For example, the
java.io.File class has another
constructor that takes two arguments: one for the parent
pathname and one for the child pathname.
We can use this constructor as follows:
import new java.io.File(String, String): ##java.io.File \ IO as newFile; newFile("foo", "HelloWorld.txt")
Here the import describes that the constructor expects two