Forums
New posts
Search forums
News
Security News
Technology News
Giveaways
Giveaways, Promotions and Contests
Discounts & Deals
Reviews
Users Reviews
Video Reviews
Support
Windows Malware Removal Help & Support
Inactive Support Threads
Mac Malware Removal Help & Support
Mobile Malware Removal Help & Support
Blog
Log in
Register
What's new
Search
Search titles only
By:
Search titles only
By:
Reply to thread
Menu
Install the app
Install
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Forums
Guides
Programming Guides & Questions
Why would you declare local variables and method arguments as "final"?
Message
<blockquote data-quote="quentisa" data-source="post: 1026280" data-attributes="member: 98424"><p>The final keyword in Java is used to qualify local variables and method arguments.</p><p>[CODE]public static void foo(final int x) {</p><p> final String qwerty = "bar";</p><p>}[/CODE]</p><p>As a result, you won't be able to reassign x and qwerty in the method's body. This technique pushes your code closer to immutability, which is typically regarded as a good thing. But, as indicated in this <a href="https://www.scaler.com/topics/java/final-keyword-in-java/" target="_blank">blog</a>, it tends to clog up code by having "final" appear everywhere. What are your thoughts on the final keyword in Java for local variables and method parameters?</p><p>The last local variables are determined by intent and, in my opinion, are less essential. It all depends on what happens.</p></blockquote><p></p>
[QUOTE="quentisa, post: 1026280, member: 98424"] The final keyword in Java is used to qualify local variables and method arguments. [CODE]public static void foo(final int x) { final String qwerty = "bar"; }[/CODE] As a result, you won't be able to reassign x and qwerty in the method's body. This technique pushes your code closer to immutability, which is typically regarded as a good thing. But, as indicated in this [URL='https://www.scaler.com/topics/java/final-keyword-in-java/']blog[/URL], it tends to clog up code by having "final" appear everywhere. What are your thoughts on the final keyword in Java for local variables and method parameters? The last local variables are determined by intent and, in my opinion, are less essential. It all depends on what happens. [/QUOTE]
Insert quotes…
Verification
Post reply
Top