Summary: | "Local variable never read" when foreach loop is used to clear an array | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Menachem Salomon <msalomon> |
Component: | Core | Assignee: | Ayushman Jain <amj87.iitr> |
Status: | VERIFIED INVALID | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | CC: | amj87.iitr, sebastian.zarnekow, srikanth_sankaran |
Version: | 3.6.2 | ||
Target Milestone: | 3.8 M4 | ||
Hardware: | PC | ||
OS: | Windows XP | ||
Whiteboard: |
Description
Menachem Salomon
2011-11-21 14:51:58 EST
I'd say the warning is correct. s = null in the foreach version will not clear the array. String[] array = new String[] {"a", "b"}; for (String s: array) s = null; for (String s: array) if (s != null) throw new RuntimeException(); (In reply to comment #1) > I'd say the warning is correct. s = null in the foreach version will not clear > the array. > > String[] array = new String[] {"a", "b"}; > for (String s: array) > s = null; > for (String s: array) > if (s != null) > throw new RuntimeException(); You're right. My oops. Can you excuse a newbie to Java programming error? BTW, I very appreciate the immediate response. (In reply to comment #2) > You're right. My oops. Can you excuse a newbie to Java programming error? > BTW, I very appreciate the immediate response. You're welcome. Thanks Sebastian! Please note that the warning has been changed to "Local variable never used" in 3.7 and above. This will make more sense now. :) |