- An instance of any class type is an object, since all classes ulitimately derive from System.Object
- Arrays are instances of a specialzation of the Generic.Array<T> template class, which is derived from System.Object. Generic.Array<T> implements the List<T> interface that provides iteration support amongst other things
- Proc references are instances of a specialization of the System.Proc<T> template class, which is derived from System.Object.
- Enumeration elements are not objects but behave as if they were instances of a specialization of the Sytem.Enum<T> class. Enumeration values can be wrapped in an instance of System.Enum<T> via the .box attribute
- Other built in value types like int and bool are not objects but behave as if they are instances of their corresponding box type (e.g. System.Int for int, System.Bool for bool) and can be wrapped in an instance of that type via the .box attribute.
Not all values in L programs are objects. However, L allows most values to be treated as objects using regular
field/accessor/method call syntax:
Source:
namespace Boxing is
use Generic.Array;
use Generic.List;
enum Things is
ROCK,
PAPER,
SCISSORS
si
class Main is
void init() is
var a = { 1, 2, 3, 4, 5 }; // a has type 'int[]'
int[] aa = a;
Generic.Array<int> ac = a; // arrays are also objects of Generic.Array type
Generic.List<int> al = a; // Generic.Array<T> implements the Generic.List<T> interface
var as = a.toString(); // Generic.Array<T> overrides System.Object.toString()
var i = 123; // i has type 'int'
var it = i.toString(); // i.toString() calls System.Int.toString(i)
var ic = i.box; // i.box creates an instance of System.Int with Value=23
var j = ic.Value;
var e = Things.ROCK;
var es = e.toString(); // e.toString() calls System.Enum<Things>.toString(e);
var ec = e.box; // e.box creates an instance of System.Enum<Things> with Value=Things.ROCK
si
si
si
site design and content copyright (C) jeek 1995-2010  
[
13132
]