On 1 March 2011 08:00, Jörg Schaible <joerg.schai...@scalaris.com> wrote: > Hi Simone, > > Simone Tripodi wrote: > > [snip] > > >> @SuppressWarnings("unchecked") >> public <T> T parse(InputSource input, Class<T> returnedType) throws >> IOException, SAXException { >> . >> . >> . >> return returnedType.cast(this.root); >> } > > It would be nice, if we can start to avoid such method global suppressions, > because it hides possibly unwanted stuff. You can always assign the > annotation directly to a variable instead: > > @SuppressWarnings("unchecked") > T t = returnedType.cast(this.root); > return t;
I would go a bit further and say that @SuppressWarnings should not be used unless you can prove that the cast is always valid (as may well be the case here - I've not checked), and that this should be documented in a // comment on the annotation, e.g. @SuppressWarnings("unchecked") // OK because etc. Otherwise, the annotation effectively gives the compiler permission to cause a ClassCastException somewhere else at some point in the future. As with many forms of suppression, the risk is that there will be a bad reaction later ... > - Jörg > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org > For additional commands, e-mail: dev-h...@commons.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org