Z
zero
When I first heard about generics I was excited. A great idea finally
available in Java. But the way they are implemented really makes no sense.
Because of type erasure generics do nothing that 1.4 code didn't already do
by using Object as "generic" class for all (sub)classes.
And the problem with arrays of generic classes? Simply ridiculous. There
is no sane reason why the following code (from a self-learning chess
program I've been working on) should not work, and yet...
ArrayList<Piece>[] board;
board = new ArrayList<Piece>[8]; // error: cannot create a generic
// array of ArrayList<Piece>
board[0] = new ArrayList<Piece>();
board[0].add(0, new Rook(false, 0, 8));
where of course Rook is a subclass of Piece.
I'm forced to use board = new ArrayList[8]; which of course gives an
unchecked warning.
They should just throw away the whole generics thing and replace it with a
C++ like approach.
available in Java. But the way they are implemented really makes no sense.
Because of type erasure generics do nothing that 1.4 code didn't already do
by using Object as "generic" class for all (sub)classes.
And the problem with arrays of generic classes? Simply ridiculous. There
is no sane reason why the following code (from a self-learning chess
program I've been working on) should not work, and yet...
ArrayList<Piece>[] board;
board = new ArrayList<Piece>[8]; // error: cannot create a generic
// array of ArrayList<Piece>
board[0] = new ArrayList<Piece>();
board[0].add(0, new Rook(false, 0, 8));
where of course Rook is a subclass of Piece.
I'm forced to use board = new ArrayList[8]; which of course gives an
unchecked warning.
They should just throw away the whole generics thing and replace it with a
C++ like approach.