Scott,

 

Thanks for the advice, and indeed, turning off Suggestions > Expand Enhanced For Loop, removes the warning 😊. I don’t then get a ‘Can use functional operations’ hint instead but that might be due to the context the for loop exists in.

 

Do you happen to know where to find hint ‘Can use functional operations’ in the Options?

 

I can’t locate something similar when looking through the lists. I prefer to use functional operations when there isn’t exception handling needed (feels messy then and so prefer the older syntax).

 

Michael,

 

  • suggestions which are only active at the current line where your cursor is, don't necessary produce better code, they are just there to transform parts of it in case you want to change something. Internally they are hints of a kind called actions.

 

Thanks for the clarification, I was wondering why some markers only appeared when the line had focus. I suppose my issue with this is probably just the icon which has an “!” implying that something is not right rather than use a different icon (e.g. ‘?’ type icon) to hint that it is offering suggestions. I couldn’t find anywhere where you could use your own icons for the hints otherwise I would amend the ‘Warning on Current Line’ one to something a little softer.

 

  • You should notice that if you change the loop to the iterator version, but not actually use the iterator except calling next() it will also add a hint called "convert to for-loop" which does the opposite.

 

I did notice that and, for me, that made it more confusing, even contradictory. But then I think that is more to do with my interpretation of the icon as I read that as ‘use best practice’ and so it was like Netbeans couldn’t make up its mind which syntax was best 🤔.

 

John

 

 

From: Scott Palmer
Sent: 28 November 2022 17:51
To: John
Cc: NetBeans Mailing List
Subject: Re: NetBeans `Convert to for (Iterator...) {}' suggestion

 

I agree that this isn’t usually a good suggestion.  It is available as a refactoring for when you might need an iterator, but by no means should the IDE “warn” about it.  I think that is the current behaviour though.  The line is not marked with a hint lightbulb unless I put the cursor on that line. So it’s not like it shows in the gutter as a warning like you would get for an unused private function or similar.

 

It appears to be the hint “Expand Enhanced For Loop” that you will find under “Suggestions” in the editor Hints panel.

 

When I turn that off the”expand” hint, the suggestion changes to  “Can use functional operations” which coverts the loop to this.dictionart.forEach(word -> {...});

 

Scott



On Nov 28, 2022, at 9:00 AM, John <jbarrow...@gmail.com> wrote:

 

Hi,

 

Quick one. I have just installed a vanilla Netbeans 15 and when I write a line such as

 

for (Word word : this.dictionary) {..}

 

Netbeans offers me a Warning / Recommendation 

 

`Convert to for (Iterator...) {}'

 

That, if chosen, converts my syntax to

 

for (Iterator<Word> it = this.dictionary.iterator(); it.hasNext();) {...}

 

This is a lot less readable to me and I therefore wanted to turn off this hint. 

 

However, The <alt><ret> doesn’t offer the option to disable this hint and I couldn’t find it in the Tools > Options > Editor > Hints (Java) list, although I found lots of other nice hints that I have turned on!  

 

I found this on Stack Overflow

 

 

But that was to do with which one is more efficient and I suspect that the warning is due to the fact that the more verbose version is quicker if the number of elements in the iterator is very large.

 

Am I stuck with this, or is it that I just overlooked where the hint is in the long list?

 

 

John

 

--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@netbeans.apache.org For additional commands, e-mail: users-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to