What happens if I declare HttpServletRequest as final & HttpServletResponse as final in a doPost method. I am trying to test that in a login page.
Asked
Active
Viewed 1,456 times
1
-
do you have an understanding of the `final` keyword? That means you will not be able to reassign the object after initialization. That's what happens when you add final to those types. – ddavison Feb 13 '14 at 16:04
-
so there will be no difference in using request1 & request2, if I declare `final HttpServletRequest request1` or `HttpServletRequest request2` – Anjigadu Feb 13 '14 at 16:08
-
@Anjigadu that's what I'm saying in my answer. – Luiggi Mendoza Feb 13 '14 at 16:08
1 Answers
0
It won't affect your application, you just can not modify their references in the doPost
method, but even if you could (by not marking them as final
) you should not even attempt to do it. It would be a very bad idea to modify these references. Still, even by declaring them as final
you can modify their state e.g. adding and removing attributes in request.
There's a good explanation about final
parameters here: final keyword in method parameters

Community
- 1
- 1

Luiggi Mendoza
- 85,076
- 16
- 154
- 332