Good afternoon all,
I was wondering what's the reason that
public class test<T> {
T[] backing_array;
public void a(int initial_capacity) {
@SuppressWarnings("unchecked")
T[] backing_array = (T[]) new Object[initial_capacity];
this.backing_array = backing_array;
}
}
is valid but
public class test<T> {
T[] backing_array;
public void b(int initial_capacity) {
@SuppressWarnings("unchecked")
this.backing_array = (T[]) new Object[initial_capacity];
}
}
is a syntax/compiler error?
What's the reason that we have to use an intermediary variable for @SuppressWarnings("unchecked")
?