As Mitch says, that syntax won't work you could possibly create a generic type called an Either, something I've used a few times in the past.
class Either<LEFT,RIGHT> {
LEFT left;
RIGHT right;
public Either(LEFT left, RIGHT right) {
if (left != null && right != null) {
throw new IllegalStateException();
}
}
public LEFT getLeft() {
return left;
}
public boolean isLeft() {
return left != null;
}
public RIGHT getRight() {
return right;
}
public boolean isRight() {
return right != null;
}
}
List<Either<Double,Char>> list = new ArrayList<Either<Double,Char>>();
It's pretty rare that this is the right approach though.