How can you get the data type of a variable argument in Java if the varg is set to null? I use the getClass to retrieve the type. Is there any other way?
public void method(String name, Object ... vargs)
{
for(Object arg : vargs)
{
mapType.put(arg.getClass());
mapVal.put(arg);
}
}
The only thing i could think of is using annotation from the calling function. Is there any other way?
We have stacked with the same problem to load data from DB and cast as expected.
Unfortunately null has no type. Instead we have used generic wrapper, that always was non-null, but could contain the null value. In this case type info is available over wrapper’s field.