Community
Participate
Working Groups
When using a collection with generics, the code assist template for "while - iterate with iterator" seems to add an unnecessary cast as well as fully qualified type names. For example, I have a map defined as follows: Map<JavaScriptError, Integer> errors; When I use the code assist template to generate a while statement (iterator), it ends up with this code: while (iterator.hasNext()) { Map.Entry<com.nr.aggregator.JavaScriptError, java.lang.Integer> entry = (Map.Entry<com.nr.aggregator.JavaScriptError, java.lang.Integer>) iterator.next(); } But, only the following is required (based on imports in the type), and is simpler to read: while (iterator.hasNext()) { Map.Entry<JavaScriptError, Integer> entry = iterator.next(); }
Can you provide more detailed steps/example, e.g. what imports are already in the source? Where do you insert the template? Also, please use types in your example that are available in the SDK.
It's pretty much the same problem as bug 102747. Needs bug 95787 for a 1.4-compatible fix. But since 1.4 has been deprecated for so long now, I guess we can also just remove the cast now. import java.util.Iterator; import java.util.List; public class E { public void m(List<Number> nums) { Iterator<Number> it= nums.iterator() while } }
Created attachment 203271 [details] Example source file attached
In the attached example, I invoked the "while - iterate with iterator" code assist template on line 16 - typed "whi" and then CTRL-space. The code filled in as shown in the source file. All required imports were already present.
*** Bug 357910 has been marked as a duplicate of this bug. ***
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.