O'Reilly logo

Java Enterprise in a Nutshell, Third Edition by William Crawford, Jim Farley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

User-Defined Data Types

In addition to the basic data types already described, IDL supports user-defined data types, which are aggregations of these basic types. These complex data types include arrays, sequences, enumerations, and constructed data types that you define yourself using structs and unions. We’ll go over each of these in detail in this section.

Complex data types are used in IDL by first giving them a type name, then using the type name wherever you would use a basic data type name or an interface type name (e.g., declaring attributes, method arguments, etc.). A name can be assigned to a complex data type in different ways:

  • With structures, unions, and enumerations, the name is included in the declaration of the data type.

  • A typedef can be used to assign a name to a specific type (basic or complex).

Before we go on to see how complex data types are declared in IDL, let’s take a look at how typedefs are used to assign type names to these complex data types.

Typedefs

A typedef is used to associate a name with another data type. The syntax of an IDL typedef is:

typedef <type_spec> <identifier>

The < type_spec > can be any basic IDL data type, a user-defined data structure (structure, union, or enumeration), an IDL interface type, or a sequence. The < identifier > can be a simple IDL identifier, or it can include dimension specifications for an array. So the following are all valid typedef statements:

// IDL typedef short myShort; typedef long longArray[2][2]; typedef PrintServer ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required