Restrictions on user-defined generics
- Last Updated: August 11, 2026
- 4 minute read
- OpenEdge
- Version 13.1
- Documentation
User-defined generics have restrictions in the following areas:
- .NET objects
CATCHstatementTHROWandRETURN ERRORENUMstatementTYPE-OFfunctionCASTfunctionGET-CLASSfunctionNEWstatement- STATIC members
The following sections describe these restrictions.
.NET objects
.NET objects cannot be used as type parameters or type arguments. For example:
|
CATCH statement
The CATCH statement does not allow a generic type or a type
parameter. For example, the following CATCH statements produce
compiler errors:
|
THROW and RETURN ERROR
You cannot use an object of a user-defined generic type to raise an error. This
restriction applies to the THROW statement and to the
RETURN ERROR option of DO ON ERROR, DO
ON QUIT, DO ON ENDKEY, and DO ON STOP
statements.
The compiler reports an error when the expression that raises an error has a
user-defined generic type. If the object is first assigned to a
Progress.Lang.AppError variable, the statement compiles but
produces a runtime error.
For example, the following THROW statement produces a compiler error because
rObj has a user-defined generic type:
|
The compiler also rejects a generic object created directly in a
THROW statement:
|
An object of a user-defined generic type can be assigned to a
Progress.Lang.AppError variable. However, throwing that
variable produces a runtime error:
|
The same restriction applies to the RETURN ERROR option of the listed
DO ON statements. For example, the following RETURN
ERROR statement produces a compiler error because rObj
has a user-defined generic type:
|
ENUM statement
ENUM types cannot be generic.
TYPE-OF and CAST functions
Within a generic class implementation, you cannot use a type parameter by itself
where a type is required by the TYPE-OF() or
CAST() built-in functions. For example:
|
In these cases, use the constraint type, instead of T. For
example:
|
GET-CLASS function
GET-CLASS() built-in function. For
example:
|
NEW statement
The NEW statement does not allow a type parameter to be used
directly. The compiler cannot validate the constructor signature because the actual
type is not known until the client of the generic class supplies a type argument.
For example:
|
You can use dynamic programming or reflection for tasks that depend on the type
argument supplied by the client of the generic type. The
Progress.Lang.Class type provides the
GetTypeArguments() method, which returns the types of the type
arguments. For example:
|
myListIterator is
Progress.Lang.Object, the NEW statement is
allowed because the constraint for T is
Progress.Lang.Object:
|
The following, more complex hierarchical example also compiles:
|
In this example, mySimpleGeneric has a type parameter constrained to
myBaseClass. Because the type parameter in
DerivedGeneric is constrained to
myDerivedClass, the variable declaration in
somemeth is valid: myDerivedClass is a
subclass of myBaseClass. If the constraints are incompatible, the
compiler raises an error.
In summary, a type parameter can be used with TYPE-OF,
CAST, GET-CLASS, and NEW only
when it is passed as a type argument to another generic type and follows the
type-compatibility rules.
STATIC members
Generic classes cannot define STATIC members including methods,
variables, properties, and events. Static members can be defined in a non-generic
class in the inheritance hierarchy, but not in the generic class itself.
You can access an inherited static member through the generic type using the
TYPE-NAME syntax. but understand that they are in the
non-generic class. However, because the member is defined by the non-generic class,
referencing that class directly is clearer. For example, given these classes:
|
Both statements are valid, but the second is clearer:
|