Constants and Literals
Literals
are explicit values inserted into IDL code. Sometimes literals are
used to specify a default value for interface attributes, or to
declare the value for a constant. Literals can be boolean
(true
or false
), numeric
(integer, floating point, or fixed point), or character-based (a
single character or a string).
Literals are most often used in IDL to initialize the value of constants. Constants are named variables that are restricted from being modified after being initialized. In IDL, a constant is declared using the syntax:
// IDL const<type spec>
<identifier>
=<value>
;
where <type spec>
is any valid basic data
type or declared interface type,
<identifier>
is any valid IDL identifier,
and <value>
is any IDL expression that
evaluates to a literal value. The initialization expression can be a
simple literal or it can be a complex expression combining multiple
literals using logical or mathematical operators. You could declare a
few useful numeric constants as follows, for example:
// IDL const float half = 1 / 2; const float quarter = 1 / 4;
Most of the operators present in C/C++, such as addition (+), subtraction (-), multiplication (*), and the logical and bitwise operators (|, &, ^, ||, &&, etc.) are supported by IDL.
Mapping Constants to Java
If
an IDL
constant is declared within an interface definition, then the
constant is mapped to a public static final static
member on the corresponding Java interface.
If the IDL constant is declared outside of ...
Get Java Enterprise in a Nutshell, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.