Mapped Types

From The Oxygene Language Wiki
Jump to: navigation, search

This is a Language topic about Oxygene
 

Language Topics Introduction | Structured Overview | Grammar | Keywords | Functions



Mapped type are a unique feature of the Oxygene language. They 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.

namespace System.Collections;
interface
uses
  java.util;

type
  List<T> = public class mapped to ArrayList<T>
  public
    method Add(o: T); mapped to add(o);
    method RemoveAt(i: Integer); mapped to remove(i);
    method Remove(o: T);
    property Length: Integer read mapped.size;
    property Item[i: Integer] read mapped[i] write mapped[i]; default;
  end;

method List<T>.Remove(o: T);
begin
  var n := mapped.IndexOf(o);
  if n >= 0 then mapped.Remove(n);
end;

This feature introduces a few new language elements. The first one is "mapped to" on the class definition, which defines which class would be used. When using List<T> the compiler will generate an ArrayList<T> at the place it's used. "mapped to" for the methods tells the compiler which method this should call at runtime, this is for simple method calls. When more advanced logic is needed like in Remove, regular code is supported. All mapped apis are inlined on use. Mapped methods cannot recursively call themselves.

Personal tools
Namespaces

Variants
Actions
Navigation
Getting Started
Sections
If you know
More
Toolbox