October 21, 2003 06:32 am

Default value expressions

Adding support for so-called default value expressions wan't really hard. Here's a small example:

public class Stack<T> { T t; public Stack (int n) { t = new T [n]; for (int i = 0; i < n; i++) t [i] = T.default; } }

The basic idea behind this is that a type parameter can either be a reference or a value type and that you may not know at compile time which one it is. This is also the reason why there is no explicit conversion between null and a type parameter.

Note that you may also use default on an arbitrary type, but the left-hand site of the default value expression must resolve to a type.

Posted by martin at October 21, 2003 06:32 am.