Restrictions on user-defined generics
- Last Updated: August 7, 2026
- 3 minute read
- OpenEdge
- Version 13.0
- Documentation
User-defined generics have restrictions in the following areas:
- .NET objects
CATCHstatementENUMstatementTYPE-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:
|
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:
|