I declared a simple class with this method amongst others :
public void setDate(final Date date);
when i get the parameters :
List<Class<?>> params = new ArrayList<Class<?>>();
params.addAll(Arrays.asList(method.getParameterTypes()));
I verify that it is final :
System.out.println("isFinal : " + Modifier.isFinal(params.get(0).getModifiers()));
But i get a false :
isFinal : false
But clearly i declared it to be final. What is the problem ?
You're asking whether the type is final
, not the parameter - and java.util.Date
isn't a final class.
Looking at the API, I can't immediately see any way of determining that a parameter is final - but that's really an implementation detail anyway. It makes no difference to the caller at all.
See more on this question at Stackoverflow