Language Extensions

RemObjects Iodine adds a few features to the Java language to make it fit better on all the platforms it supports. We try to keep these extensions to a minimum, and tastefully within the design aesthetics of the Java language.

Where additional keywords are needed, we follow the C-style language convention of prefixing these with two underscores ("__") to avoid conflict with future changes to the official Java language.

Type Inference

Parallelling its use in the C# language, the var keyword can be used to replace a concrete type in field and variable declarations, to leverage type inference:

Foo x = new Foo(); // classic Java
var x = new Foo(); // use Type Inference

Multi-Part Method and Constructor Names

In order to fit in well with the API conventions on the Cocoa platform, Iodine (like C# and Oxygene) adds support for multi-part method names — essentially the ability for a method's name to be split into separate parts, each followed by a distinct parameter. This feature is available on all platforms, and described in more detail in the Multi-part method names topic.

Not-Nullable Types

In Iodine, both value and reference type variables can be adorned by the ? operator to mark them as "nullable" and with the ! operator to mark them as "not nullable". See the Nullability topic in the Language Concepts section for more details, and Non-Nullable Types for a more explicit discussion of the Java syntax (which mirrors nullable types in our C# dialect).

The ! operator can also be used to force a nullable expression to be non-nullable.

int? foo = null;
String! bar = "Hello";

Properties

Iodine extends the Java language to allow the definition of true properties that can be accessed like fields using the . syntax, invoking optional getter or setter code. In addition. Methods named get* and set* imported from external libraries will automatically be made accessible using property syntax as well. Defining custom properties uses a syntax similar to C#, but with the __get and __set keywords.

Cocoa-specific Features

RemObjects C# adds the __strong, __weak and __unretained type modifiers to control how the lifetime of Automatic Reference Counted objects is handled on Cocoa. The modifiers are described in the Storage Modifiers topic.

Finally, __selector() can be used to create a selector instance on Cocoa, for use in functions that take such a selector for callback purposes, and for dynamic dispatch of method calls in the Objective-C runtime environment. This is described here.

Aspects & Attributes

Aspects are special attributes that influence how the compiler emits the final executable. In RemObjects C#, they use attributes syntax and the optional __aspect: attribute prefix. Aspects are covered in more detail in their own section, including how to use them and how to create your own.

The __assembly and __module prefixes are allowed for attributes, to mark them as pertaining to the assembly or the module, respectively. These work the same way they do in Swift, C# and Oxygene, eg:

@__assembly:AssemblyTitle("My Application")

Global Members

Mostly to fit in better with Cocoa and Island, but available on all platforms, Iodine allows you to both call and define global methods (functions) and variables that are not contained within a class.

Structs

Using the __struct keyword, Iodine allos the declaration of structs, which are stack-based value types that otherwise behave similer to classes and can contain fields, properties and methods.

public __struct Point
{
    public double x;
    public double y;
    public double distanceTo(Point other) { ... }
}

Extension Types

Type extensions can be used to expand an existing type with new methods or properties.

public __extension class String_Helpers extends String
{
    public String reverse() { ... }
}

Partial Classes

Partial Classes allow a single class (or struct) to be declared spanning multiple source files.

public __partial class Window1 extends System.Windows.Window
{
    public String reverse() { ... }
}

Out and By-Reference Parameters

Iodine extends Java with support for both in-out and out-only by-reference parameters, using the __ref and __out keywords. These work symetrilal to ref/out in C# and Java or var/out in Oxygene, and need to be specified both in the declaration and at the call site:

public void getValues(__out String foo, __ref String bar) { ... }

...

String f;
String b = "Hello";
getValues(__out f, __ref b);

Version Notes

Support for __struct is new in Elements 9.3.

New in v10

properties

__selector

storage modifiers

__block

Swift-style keyword escaping