|
|
|
|
|
|
| Basics | Objects | Types | Hello World |
We now want to introduce to you the basics of ACDK.
To create a new Object use 'new'.
Save the new Object in a Reference.
A Reference to an Object instance is
typed by R+ClassName. For StringBuffer
the type of the Reference is RStringBuffer.
{
RStringBuffer sb = new StringBuffer();
}
|
Unlike in Java, accessing methods is different,
if the method is static or non- static.
{
RStringBuffer sb = new StringBuffer();
sb->append("Hi"); // non static call
RString str = String::valueOf(3.4); // static call
}
|
Normally, it is not a good idea to
access Class Fields directly without a
set/get method wrapper.
Object should be destroyed. They will automatically
be destroyed, if the last Reference to the
object is lost.
As an alternative, you can also asign Nil to the
the reference:
{
RStringBuffer sb1 = new StringBuffer("M");
sb1->append("JA");
sb1 = Nil;
// sb1 does not hold StringBuffer, StringBuffer will be removed
}
|
If you want to dublicate a reference, you can easily use:
{
RStringBuffer sb1 = new StringBuffer("M");
RStringBuffer sb2 = sb1; // sb2 contains the same StringBuffer instance
sb2->append("A");
sb1->append("JA"); // StringBuffer now contains "ACDK"
}
|
See also: References.
In ACDK the same mechanism will be used for copy instances (not
only reference).
{
RStringBuffer sb1 = new StringBuffer("M");
RStringBuffer sb2 = sb1->clone(); // sb2 contains a dublicate
sb2->append("A");
sb1->append("JA");
// sb2 refer to "MA"
// sb1 refer to "AJA"
}
|
With default, only references will be passed as
method argument or return value.
They are similiar to rules found in Java.
RInteger myParse(RStringBuffer arg)
{
RString str = arg->toString();
RInteger erg = Integer::parseInt(str);
return erg;
}
// same, but more 'inlined' version
RInteger myParse(RStringBuffer arg)
{
return Integer::parseInt(arg->toString());
}
|
|
|