IntelliJ IDEA underlines variables when using += in JAVA2019 Community Moderator ElectionHow can I permanently enable line numbers in IntelliJ?Is Java “pass-by-reference” or “pass-by-value”?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?What is the scope of variables in JavaScript?How to determine if variable is 'undefined' or 'null'?How do I convert a String to an int in Java?IntelliJ inspection gives “Cannot resolve symbol” but still compiles codeCreating a memory leak with JavaHow to see JavaDoc in IntelliJ IDEA?

Why are special aircraft used for the carriers in the United States Navy?

PTIJ: Mouthful of Mitzvos

The past tense for the quoting particle って

Why won't the strings command stop?

Is this nominative case or accusative case?

Why is there an extra space when I type "ls" on the Desktop?

Does the in-code argument passing conventions used on PDP-11's have a name?

What is the purpose of a disclaimer like "this is not legal advice"?

Should we avoid writing fiction about historical events without extensive research?

Did Amazon pay $0 in taxes last year?

Why would the IRS ask for birth certificates or even audit a small tax return?

“I had a flat in the centre of town, but I didn’t like living there, so …”

What does "rhumatis" mean?

If nine coins are tossed, what is the probability that the number of heads is even?

Dukha vs legitimate need

Can a space-faring robot still function over a billion years?

How to make sure I'm assertive enough in contact with subordinates?

How spaceships determine each other's mass in space?

PTiJ: How should animals pray?

Are there other characters in the Star Wars universe who had damaged bodies and needed to wear an outfit like Darth Vader?

How do we objectively assess if a dialogue sounds unnatural or cringy?

Called into a meeting and told we are being made redundant (laid off) and "not to share outside". Can I tell my partner?

Remove object from array based on array of some property of that object

Align equations with text before one of them



IntelliJ IDEA underlines variables when using += in JAVA



2019 Community Moderator ElectionHow can I permanently enable line numbers in IntelliJ?Is Java “pass-by-reference” or “pass-by-value”?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?What is the scope of variables in JavaScript?How to determine if variable is 'undefined' or 'null'?How do I convert a String to an int in Java?IntelliJ inspection gives “Cannot resolve symbol” but still compiles codeCreating a memory leak with JavaHow to see JavaDoc in IntelliJ IDEA?










13















Since the new update (2018.2) IntelliJ IDEA underlines variables, when they are "unnecessarily" reassigned - this includes, however, each use of "+=".

Is this a mistake in the IDE or am I getting it wrong?

Please see this basic method as an example. (It just adds a list of numbers.)



example image










share|improve this question




























  • I'm not sure, but if you use jdk 10 these underlings may suggest you that you can use var instead of int.

    – zlakad
    Aug 5 '18 at 18:32











  • Thanks for the reply. I actually downgraded to jdk 8/1.8, because nobody could open my jar :)

    – fandango
    Aug 5 '18 at 18:34






  • 1





    Well, it is unnecessary reassignment in the sense that you could just use a stream to calculate it... But I don't see that you are doing anything unusual there.

    – Andy Turner
    Aug 5 '18 at 18:46
















13















Since the new update (2018.2) IntelliJ IDEA underlines variables, when they are "unnecessarily" reassigned - this includes, however, each use of "+=".

Is this a mistake in the IDE or am I getting it wrong?

Please see this basic method as an example. (It just adds a list of numbers.)



example image










share|improve this question




























  • I'm not sure, but if you use jdk 10 these underlings may suggest you that you can use var instead of int.

    – zlakad
    Aug 5 '18 at 18:32











  • Thanks for the reply. I actually downgraded to jdk 8/1.8, because nobody could open my jar :)

    – fandango
    Aug 5 '18 at 18:34






  • 1





    Well, it is unnecessary reassignment in the sense that you could just use a stream to calculate it... But I don't see that you are doing anything unusual there.

    – Andy Turner
    Aug 5 '18 at 18:46














13












13








13


2






Since the new update (2018.2) IntelliJ IDEA underlines variables, when they are "unnecessarily" reassigned - this includes, however, each use of "+=".

Is this a mistake in the IDE or am I getting it wrong?

Please see this basic method as an example. (It just adds a list of numbers.)



example image










share|improve this question
















Since the new update (2018.2) IntelliJ IDEA underlines variables, when they are "unnecessarily" reassigned - this includes, however, each use of "+=".

Is this a mistake in the IDE or am I getting it wrong?

Please see this basic method as an example. (It just adds a list of numbers.)



example image







java variables intellij-idea underline






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 5 '18 at 19:50









CrazyCoder

278k50657664




278k50657664










asked Aug 5 '18 at 18:29









fandangofandango

686




686

















  • I'm not sure, but if you use jdk 10 these underlings may suggest you that you can use var instead of int.

    – zlakad
    Aug 5 '18 at 18:32











  • Thanks for the reply. I actually downgraded to jdk 8/1.8, because nobody could open my jar :)

    – fandango
    Aug 5 '18 at 18:34






  • 1





    Well, it is unnecessary reassignment in the sense that you could just use a stream to calculate it... But I don't see that you are doing anything unusual there.

    – Andy Turner
    Aug 5 '18 at 18:46


















  • I'm not sure, but if you use jdk 10 these underlings may suggest you that you can use var instead of int.

    – zlakad
    Aug 5 '18 at 18:32











  • Thanks for the reply. I actually downgraded to jdk 8/1.8, because nobody could open my jar :)

    – fandango
    Aug 5 '18 at 18:34






  • 1





    Well, it is unnecessary reassignment in the sense that you could just use a stream to calculate it... But I don't see that you are doing anything unusual there.

    – Andy Turner
    Aug 5 '18 at 18:46

















I'm not sure, but if you use jdk 10 these underlings may suggest you that you can use var instead of int.

– zlakad
Aug 5 '18 at 18:32





I'm not sure, but if you use jdk 10 these underlings may suggest you that you can use var instead of int.

– zlakad
Aug 5 '18 at 18:32













Thanks for the reply. I actually downgraded to jdk 8/1.8, because nobody could open my jar :)

– fandango
Aug 5 '18 at 18:34





Thanks for the reply. I actually downgraded to jdk 8/1.8, because nobody could open my jar :)

– fandango
Aug 5 '18 at 18:34




1




1





Well, it is unnecessary reassignment in the sense that you could just use a stream to calculate it... But I don't see that you are doing anything unusual there.

– Andy Turner
Aug 5 '18 at 18:46






Well, it is unnecessary reassignment in the sense that you could just use a stream to calculate it... But I don't see that you are doing anything unusual there.

– Andy Turner
Aug 5 '18 at 18:46













1 Answer
1






active

oldest

votes


















18














It's a new feature of IntelliJ IDEA 2018.2:



Underlining reassigned local variables and reassigned parameters



IntelliJ IDEA now underlines reassigned local variables and reassigned parameters, by default. The attributes for all the languages supporting this feature, which for now include Java and Groovy, can be changed in Preferences/Settings | Editor | Color Scheme | Language Defaults | Identifiers | Reassigned.



underline



Why it may be useful?



If the variable/parameter is underlined, you know that you can't use it in lambda/anonymous class directly.



When reading a very long method code, if the parameter is not underlined, you know for sure that its value is not reassigned anywhere in this method and it contains exactly the same value that was passed to this method at any point.



Some code guidelines are against reassigned variables and you may want to avoid them where possible to keep the code clean and make it easier to read/debug.



Nowadays many developers prefer to avoid mutable state, and reassign variables only in rare cases when it is really necessary. We don't want to manually enforce immutability, we suppose that everything is immutable by default and want to bring additional attention to the cases when something is not. If you use final to mark non-mutable variables it means that you need to write more code for regular cases and less code in exceptional cases. (BTW in modern languages declaring immutable variables doesn't require writing additional code, but unfortunately not in Java).



Brian Goetz, Java Language Architect, also likes the way IntelliJ IDEA highlights reassigned variables (see his tweet).






share|improve this answer




















  • 1





    It's basically what final can be used for (only not everybody uses it)

    – ACV
    Jan 29 at 15:32











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51697168%2fintellij-idea-underlines-variables-when-using-in-java%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









18














It's a new feature of IntelliJ IDEA 2018.2:



Underlining reassigned local variables and reassigned parameters



IntelliJ IDEA now underlines reassigned local variables and reassigned parameters, by default. The attributes for all the languages supporting this feature, which for now include Java and Groovy, can be changed in Preferences/Settings | Editor | Color Scheme | Language Defaults | Identifiers | Reassigned.



underline



Why it may be useful?



If the variable/parameter is underlined, you know that you can't use it in lambda/anonymous class directly.



When reading a very long method code, if the parameter is not underlined, you know for sure that its value is not reassigned anywhere in this method and it contains exactly the same value that was passed to this method at any point.



Some code guidelines are against reassigned variables and you may want to avoid them where possible to keep the code clean and make it easier to read/debug.



Nowadays many developers prefer to avoid mutable state, and reassign variables only in rare cases when it is really necessary. We don't want to manually enforce immutability, we suppose that everything is immutable by default and want to bring additional attention to the cases when something is not. If you use final to mark non-mutable variables it means that you need to write more code for regular cases and less code in exceptional cases. (BTW in modern languages declaring immutable variables doesn't require writing additional code, but unfortunately not in Java).



Brian Goetz, Java Language Architect, also likes the way IntelliJ IDEA highlights reassigned variables (see his tweet).






share|improve this answer




















  • 1





    It's basically what final can be used for (only not everybody uses it)

    – ACV
    Jan 29 at 15:32
















18














It's a new feature of IntelliJ IDEA 2018.2:



Underlining reassigned local variables and reassigned parameters



IntelliJ IDEA now underlines reassigned local variables and reassigned parameters, by default. The attributes for all the languages supporting this feature, which for now include Java and Groovy, can be changed in Preferences/Settings | Editor | Color Scheme | Language Defaults | Identifiers | Reassigned.



underline



Why it may be useful?



If the variable/parameter is underlined, you know that you can't use it in lambda/anonymous class directly.



When reading a very long method code, if the parameter is not underlined, you know for sure that its value is not reassigned anywhere in this method and it contains exactly the same value that was passed to this method at any point.



Some code guidelines are against reassigned variables and you may want to avoid them where possible to keep the code clean and make it easier to read/debug.



Nowadays many developers prefer to avoid mutable state, and reassign variables only in rare cases when it is really necessary. We don't want to manually enforce immutability, we suppose that everything is immutable by default and want to bring additional attention to the cases when something is not. If you use final to mark non-mutable variables it means that you need to write more code for regular cases and less code in exceptional cases. (BTW in modern languages declaring immutable variables doesn't require writing additional code, but unfortunately not in Java).



Brian Goetz, Java Language Architect, also likes the way IntelliJ IDEA highlights reassigned variables (see his tweet).






share|improve this answer




















  • 1





    It's basically what final can be used for (only not everybody uses it)

    – ACV
    Jan 29 at 15:32














18












18








18







It's a new feature of IntelliJ IDEA 2018.2:



Underlining reassigned local variables and reassigned parameters



IntelliJ IDEA now underlines reassigned local variables and reassigned parameters, by default. The attributes for all the languages supporting this feature, which for now include Java and Groovy, can be changed in Preferences/Settings | Editor | Color Scheme | Language Defaults | Identifiers | Reassigned.



underline



Why it may be useful?



If the variable/parameter is underlined, you know that you can't use it in lambda/anonymous class directly.



When reading a very long method code, if the parameter is not underlined, you know for sure that its value is not reassigned anywhere in this method and it contains exactly the same value that was passed to this method at any point.



Some code guidelines are against reassigned variables and you may want to avoid them where possible to keep the code clean and make it easier to read/debug.



Nowadays many developers prefer to avoid mutable state, and reassign variables only in rare cases when it is really necessary. We don't want to manually enforce immutability, we suppose that everything is immutable by default and want to bring additional attention to the cases when something is not. If you use final to mark non-mutable variables it means that you need to write more code for regular cases and less code in exceptional cases. (BTW in modern languages declaring immutable variables doesn't require writing additional code, but unfortunately not in Java).



Brian Goetz, Java Language Architect, also likes the way IntelliJ IDEA highlights reassigned variables (see his tweet).






share|improve this answer















It's a new feature of IntelliJ IDEA 2018.2:



Underlining reassigned local variables and reassigned parameters



IntelliJ IDEA now underlines reassigned local variables and reassigned parameters, by default. The attributes for all the languages supporting this feature, which for now include Java and Groovy, can be changed in Preferences/Settings | Editor | Color Scheme | Language Defaults | Identifiers | Reassigned.



underline



Why it may be useful?



If the variable/parameter is underlined, you know that you can't use it in lambda/anonymous class directly.



When reading a very long method code, if the parameter is not underlined, you know for sure that its value is not reassigned anywhere in this method and it contains exactly the same value that was passed to this method at any point.



Some code guidelines are against reassigned variables and you may want to avoid them where possible to keep the code clean and make it easier to read/debug.



Nowadays many developers prefer to avoid mutable state, and reassign variables only in rare cases when it is really necessary. We don't want to manually enforce immutability, we suppose that everything is immutable by default and want to bring additional attention to the cases when something is not. If you use final to mark non-mutable variables it means that you need to write more code for regular cases and less code in exceptional cases. (BTW in modern languages declaring immutable variables doesn't require writing additional code, but unfortunately not in Java).



Brian Goetz, Java Language Architect, also likes the way IntelliJ IDEA highlights reassigned variables (see his tweet).







share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered Aug 5 '18 at 19:49









CrazyCoderCrazyCoder

278k50657664




278k50657664







  • 1





    It's basically what final can be used for (only not everybody uses it)

    – ACV
    Jan 29 at 15:32













  • 1





    It's basically what final can be used for (only not everybody uses it)

    – ACV
    Jan 29 at 15:32








1




1





It's basically what final can be used for (only not everybody uses it)

– ACV
Jan 29 at 15:32






It's basically what final can be used for (only not everybody uses it)

– ACV
Jan 29 at 15:32




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51697168%2fintellij-idea-underlines-variables-when-using-in-java%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко