You could return a new Vector<X>()
, but a better solution would be to move away from Vector
which has been obsolete for (many) years. Unless you require concurrency features, you can use an ArrayList
instead.
You added that you receive the Vector
from a third party service. Don't forget that a Vector
is a List
, so you could maybe use something like this:
public List<X> getData() {
try {
Vector<X> v = getDataFromService();
return v;
} catch (ServiceException e) {
return Collections.emptyList();
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…