java - Unchecked casts and unnecessary suppressed warnings with lambdas -


while working lambdas , generics, encountered special case of unsafe cast warnings.

during reproducing , making sscce, found related fact lambda "inside" return statement.

the question is: why warning in warningunnecessarysuppresswarnings method?. when removing @suppresswarnings("unchecked"), get:

type safety: unchecked cast list list

as shown in warningunsafecast method. because of this, annotation not unnecessary new warning says.

i using eclipse kepler sp2 java ee developers, build id: 20140224-0627

also using the recommended update-site java 8 support in eclipse kepler

public static void main(string[] args) {     system.out.println(warningunnecessarysuppresswarnings());     system.out.println(warningunsafecast());     system.out.println(withoutwarning()); }  private static integer perform(function<list<?>, integer> func) {     return func.apply(arrays.aslist("a", "b", "c")); }  private static integer warningunnecessarysuppresswarnings() {     return perform(list -> {         @suppresswarnings("unchecked") // unnecessary @suppresswarnings("unchecked")         list<string> unsafecast = (list<string>) list;         return unsafecast.size();     }); }  private static integer warningunsafecast() {     return perform(list -> {         list<string> unsafecast = (list<string>) list; // type safety: unchecked cast list<capture#4-of ?> list<string>         return unsafecast.size();     }); }  @suppresswarnings("unchecked") private static integer withoutwarning() {     return perform(list -> {         list<string> unsafecast = (list<string>) list;         return unsafecast.size();     }); } 

the code in question type-unsafe , therefore should generate warning. @suppresswarnings annotation of course necessary suppress warning.

it apparently bug in eclipse kepler sp2 issues warning statement, warns @suppresswarnings unnecessary when annotation added.

the workaround disable "unnecessary @suppresswarning" warning in eclipse compiler configuration.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -