Object Variables
Description
Object variables are similar to string, numeric and integer variables; they act as holders for data. An object variable is a universal holder; it can contain any kind of data. Object variables are distinguished from other variable types by an exclamation mark at the end of the name. Some examples of object variables are:
X! = "The quick
brown fox" |
In this example, X! is an object variable that contains a string value. It can be used almost everywhere a string variable can be used. For example:
PRINT X!; REM ' this is equivalent to PRINT X!.toString() |
To avoid conflict between BBj template and substring syntax versus object syntax, object variables cannot be dimensioned with string templates, and they do not support BBx substring notation.
All of the following examples are syntax errors:
DIM X!:"FIELD:C(1*)"; REM ' can't dim
object variable with a template |
Object variables cannot be used in INPUT or DREAD statements.
Y! is an object variable that contains a numeric value. In can be used almost everywhere a numeric variable can be used. For example:
PRINT Y!:"###.00"; REM ' prints "
12.95" |
An object variable is treated as a number if it was created from a numeric
expression, or from a Java call that returned a Java primitive type (boolean,
byte, char, short, int, long, float or double). A boolean value of false
becomes zero and a boolean value of true becomes one.
See Calling Java From BBj for more
details.
Z! is a Java object. There are several ways to create a Java object. The first method is to use the 'new' operator. This works the same way in BBj as in Java:
map! = new java.util.HashMap()
|
The BBjAPI() function is an entry point to many object-oriented features of the BBj language. For example:
BBJAPI! = bbjapi()
|
Public attributes of an object can be accessed using dot notation. For example:
DIM! = new
java.awt.Dimension(10,20)
|
Public methods of an object can be accessed using dot notation. For example:
A! = new java.util.ArrayList()
|
Static attributes and methods of any Java class can also be accessed. For example:
System.out.println("message sent
to stdout")
|
The NULL() Function returns a Java null value. This can be used to compare a returned value to null. For example:
0010 h! = new java.util.HashMap()
|
Uninitialized object variables are equal to null:
>START |
For More Information
For information about specific language features that have been enhanced for object variables, see:
CALL Verb - BBj-Specific Information
DEF Verb - BBj-Specific Information
DIM Verb - BBj-Specific Information
ENTER Verb - BBj-Specific Information
FNx() Function - BBj-Specific Information
LET Verb - BBj-Specific Information
NUM() Function - BBj-Specific Information
SETTRACE Verb - BBj-Specific Information