Hi John,

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.

The doc describes it well:

"The hint (with kind ACTION) represents an offer to the user to automatically alter the code. The transformation is not intended to improve the code, only allow the user to do some kind of code transformation quickly. The only meaningful severity for suggestions if Severity.CURRENT_LINE_WARNING."

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. This hint will always appear, even if you move the cursor, since unless you actually need the iterator the simple for loop is more readable and should be preferred as you said.

the for-each loop uses a hidden iterator if it iterates over iterables anyway.

I don't know why you can't disable this particular suggestion via the context menu.

regards,
michael


On 28.11.22 15:00, John 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

https://stackoverflow.com/questions/24263479/netbeans-convert-to-for-iterator-suggestion

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