4.3. Interacting with Java

When a Java class is made accessible to Orc using the class declaration, the Orc typechecker interacts with the Java type system to make Java types available in Orc. This feature is experimental and does not allow access to all of Java's typing features (for example, interfaces are not fully supported), but it does allow the typechecker to handle many of the common cases.

The type returned by the constructor of a class has the same name in Orc as the class. It is the Orc type of Java objects of that class.

class File = java.io.File
File("test.orc") :: File

If a class declaration binds a generic Java class, that type shows up in Orc as a parametric type, and its constructor takes type arguments. For example:

class TreeSet = java.util.TreeSet
TreeSet[String]() :: TreeSet[String]

There is a correspondence between Orc's primitive types and the equivalent classes in Java; they are interchangeable. For example, a call expecting a java.lang.Integer can be given an Orc Integer.

Subtyping between Java object types is determined by Java's subtyping relation: if one class is a subclass of the other, then one type will be a subtype of the other. The typechecker does not implement support a full join operation for Java types; it will not find the least common ancestor of two classes as the join.