Structs

Iodine extends the Java language with the ability to declare Structs. Like in C#, Swift, Go and Mercury, and Records in Oxygene, Structs are comparable to Classes in that they represent a data structure that combines Fields and Methods. Unlike Classes, Structs are stack-based value types, and while they do support inheritance, they do not offer polymorphism.

A struct is declared very similar to a class, except by replacing the class keyword with __struct:

MyStruct = public _struct {
    public int count;
    public void DoSomething() {
        ..
    }
}

Structs may provide an ancestor via extends, but they may not declare virtual or overriden members.

Except when using the Toffee compiler back-end for Cocoa, they may also implement interfaces using the same implements syntax as used for classes.

MyStruct2 = public _struct extends MyStruct implements IFoo {
    public string name;
    public void DoSomethingElse() {
        ..
    }
    
    ..
}

In the example above, MyStruct2 contains all the fields and methods of MyStruct, as well as those defined for MyStruct2 itself.

See Also