java - Using @SuppressWarnings within method generates compile error -
i have following code block:
final map<string, double> map; if (cond) { int currency = 44; @suppresswarnings("unchecked") map = (map<string, double>)objecta.get(); }else { map= ....} get() method of objecta returns raw hashmap(i know nice use generics there , problem solved, cannot change code class). if remove @suppresswarnings("unchecked") line, typesafety warning. when add supress warning in line right bellow assignment, following error :
map cannot resoved type! could explain me why?
the compiler thinks @suppresswarnings("unchecked") expression , there's no terminal operator ;. however, if add it, expression invalid.
you have annotate method or use annotation before variable definition:
@suppresswarnings("unchecked") public void method() { @suppresswarnings("unchecked") final map<string, double> map; if (cond) { int currency = 44; map = (map<string, double>)objecta.get(); } } note javadoc suggests that:
as matter of style, programmers should use annotation on nested element effective.
Comments
Post a Comment