O
O.B.
Why does the cast in the following code snippet fail?
private InternetAddress[] getAddressAsArray(String address) {
List emails = new LinkedList();
String[] addresses = address.split(",");
for (int i = 0; i < addresses.length; i++) {
String tempAddress = addresses.trim();
if ( 0 < tempAddress.length()) {
try {
emails.add(new InternetAddress(tempAddress));
} catch (AddressException e) {
logger.error(e);
}
}
}
InternetAddress[] blah = null;;
try {
// Why is this causing a class cast exception?
blah = (InternetAddress[])emails.toArray();
} catch (RuntimeException e) {
logger.error(e);
}
return blah;
}
private InternetAddress[] getAddressAsArray(String address) {
List emails = new LinkedList();
String[] addresses = address.split(",");
for (int i = 0; i < addresses.length; i++) {
String tempAddress = addresses.trim();
if ( 0 < tempAddress.length()) {
try {
emails.add(new InternetAddress(tempAddress));
} catch (AddressException e) {
logger.error(e);
}
}
}
InternetAddress[] blah = null;;
try {
// Why is this causing a class cast exception?
blah = (InternetAddress[])emails.toArray();
} catch (RuntimeException e) {
logger.error(e);
}
return blah;
}