Is it possible to find out, if the parameter of method is final
?
I have tried this:
int modifiers = method.getParameters()[0].getModifiers() // modifiers == 0
But even if first parameter has final
modifier, modifiers
is set to zero.
edit: I really don't think that my question is a duplicate. When I try this code with members of class (such as fields, methods, etc.), it works perfectly. But with method parameters getModifiers
fails!
edit2: In questions you suggested me as similar I didn't find an answer... So could you help me, how to check if parameter is final?
After a brief study I am afraid that it is not possible. See first comment on this question
I tried to find more proof on this but failed on that. Anyway I made a small test based on the 1st suggested dubes answer.
Having test class like
and running this test/logging
logs
so it seems that the only allowed method parameter modifier
final
does not exist in compiled method declaration. Note that it neither exists in logged methods signatureFrom source code of
Modifier
and
and
so to tell that method parameter was declared as
final
the second bit should be 1.