Community
Participate
Working Groups
In the following sample, 'Organize imports' adds the useless static imports : package sample; import static sample.Test.TestEnum.V1; import static sample.Test.TestEnum.V2; public class Test<T> { public static enum TestEnum { V1, V2 } public void test(final TestEnum value) { switch (value) { case V1: case V2: } } public void ref() { final TestEnum v1 = TestEnum.V1; final TestEnum v2 = TestEnum.V2; } } The confusion results from the combination of the switch statement, the embedded TestEnum class, and the generic Test class. Removing the switch statement (while keeping the other references to TestEnum), turning TestEnum into a top level class or removing the type parameter of Test makes the useless imports disappear. Hopefully, those imports don't prevent compilation. However, the fields of the enum are reported to hide some other elements (ironically, they are hiding themselves) : The field Test<T>.TestEnum.V1 is hiding a field from type Test.TestEnum
Compiled with -warn:hiding reports: ---------- 1. WARNING in D:\tests_sources\sample\Test.java (at line 8) V1, ^^ The field Test<T>.TestEnum.V1 is hiding a field from type Test.TestEnum ---------- 2. WARNING in D:\tests_sources\sample\Test.java (at line 9) V2 ^^ The field Test<T>.TestEnum.V2 is hiding a field from type Test.TestEnum ---------- 2 problems (2 warnings) Removing the two imports fixes it.
Bug 165081 has been added to track the unused import problem.
Created attachment 54166 [details] Proposed patch
Added StaticImportTest#test047
Released for 3.3M4 Fixed
Verified for 3.3M4 with I20061211-1119
Changing OS from Mac OS to Mac OS X as per bug 185991