Does Foreach help use class variables?

If I use fore-each-template for the following values ​​using

  • f o r e Ctrl + Space Enter Enter on line 5
  • f o r e Ctrl + Space Enter Tab Tab Down Enter on line 8
  • f o r e Ctrl + Space Enter Tab Tab Down Down Enter on line 11

the following code will be created (by Eclipse 4.2)

01 public static String[] c = new String[]{"hi"}; 02 public static void test() { 03 String[] a = new String[]{"hi"}; 04 int[] b = new int[]{2}; 05 for (String string : a) { 06 // 1. fine 07 } 08 for (int i : b) { 09 // 2. fine too 10 } 11 for (iterable_type iterable_element : c) { 12 // 3. not resolved? 13 } 14 } 

Now the question is:

  • Why can not Array c resolve its Array-Type and name?
  • Could this be a bug in Eclipse?
+4
source share
1 answer

In the while template,

 while (${condition:var(boolean)}) { ${line_selection}${cursor} } 

${condition:var(boolean)} matches members and static members. Note that content-assist for var says:

$ {ID: var (type [, type] *)} Computes a field, local variable, or parameter visible in the current scope, which is a subtype of any given type. If no type is specified, primitive variables.

In the foreach template, the template variable is different:

 for (${iterable_type} ${iterable_element} : ${iterable}) { ${cursor} } 

Document for the variable ${iterable} :

Suggestion for iteration (array or java.lang.Iterable)

It is not indicated whether (static) members should be proposed or not.

EDIT: This documentation page claims to

$ {iterable} Computes the sentence for a repeating or array visible in the current area.

Thus, according to the document, this may actually be a mistake. In fact, this has already been reported here .

+1
source

Source: https://habr.com/ru/post/1497963/


All Articles