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

Paralleling 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";

Events & Blocks

Support for .NET-style multi-cast Events is provided to allow Swift code to fully participate in the .NET event system, including support for Block Types via the __event and __block keywords.

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.

Structs

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

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

Cocoa-Specific Features

Iodine 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. The try ( __autoreleasepool) can be used to manually control ARC auto-release pools.

__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.

Mapped Types

Mapped Types let you create compatibility wrappers for types without ending up with classes that contain the real type. The wrappers will be eliminated by the compiler and rewritten to use the type the mapping maps to.

Extension Types

Extensions Types can be used to expand an existing type with new methods or properties.

Partial Classes

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

Aspects & Attributes

Aspects are special attributes that influence how the compiler emits the final executable. Aspects are covered in more detail in their own section, including how to use them and how to create your own.

Class Contracts

Class Contracts allow code to become self-testing, with Pre- and Post-Conditions for methods and type-wide Invariants.

Conditional Compilation

Iodine allows the use of compiler directives such as #if to compile code conditionally – be it for different platforms, or just different project configurations.

Smaller Changes

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.

Array Literals

Iodine allows the declaration of Array Literals using curly braces. On Cocoa, they are assignment compatible with NSArray, as well.

int[] myIntArray1 = new int[3];
int[] myIntArray2 = {1,2,3};
int[] myIntArray3 = new int[]{1,2,3};

myIntArray1 = new int[3];
myIntArray3 = new int[]{1,2,3};
myIntArray2 = {1,2,3};

NSArray array1 = {1,2,3};

Pointers

Iodine supports pointers on Cocoa, Island and on .NET with Unsafe Code enabled, using the same syntax as familiar from C and C#. The * operator can be used to dereference pointers, and to annotate pointer types; & can be used to obtain the address of objects.

int a = 8;
int *anIntPointer;
anIntPointer = &a;
*anIntPointer = 5;

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 symmetrical to ref/out in C# 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);

Swift-style keyword Escaping

Keywords can be used as identifiers if surrounded by back-ticks – same as in Swift:

var `if` = 5;