Generics, Defining - in COBOL and Java

Table 1. Defining
COBOL Java
*> Generic interface
interface-id IPoint using T
method-id makePoint using T (x as T, y as T, z as T).
end method.
end interface.

*> Generic class
class-id Point using T, N.
01 varT T public.
01 varN N public.
end class.

*> Generic class with constraints
class-id ConstrainedPoint using T.
constraints.
constrain T implements type IPoint[binary-double].
method-id makeConstrainedPoint using N (x as N).
constraints.
    constrain N implements type IPoint[binary-double].

end method.
end class.

*> Class with generic interface
class-id PointImpl
    implements type IPoint[binary-double].
method-id makePoint using T (x as T, y as T, z as T).

end method.
end class.
// Generic interface
interface IPoint<T> {
    void makePoint(T x, T y, T z);
}

// Generic class
class Point<T, N> {
    public T varT;
    public N varN;
}

// Generic class with constraints
class ConstrainedPoint<T extends IPoint<Long>> {
    <N extends IPoint<Long>> void makeConstrainedPoint(N x) {

    }
}

// Class with generic interface
class PointImpl implements IPoint<Long> {

    @Override
    public void makePoint(Long x, Long y, Long z) {

    }
}

Portions of these examples were produced by Dr. Frank McCown, Harding University Computer Science Dept, and are licensed under a Creative Commons License.