I am having trouble understanding where exactly or the annotation can be placed.
A class with this method compiles, but gives a warning "unchecked":
<B extends BitSet> void doStuff(LinkedList<B> list) { B board = list.getFirst(); B cloneBoard; cloneBoard = (B) board.clone();
This compiles without warning:
<B extends BitSet> void doStuff(LinkedList<B> list) { B board = list.getFirst(); @SuppressWarnings("unchecked") B cloneBoard = (B) board.clone(); }
This does not compile, but notes cloneBoard with an error:
<B extends BitSet> void doStuff(LinkedList<B> list) { B board = list.getFirst(); B cloneBoard; @SuppressWarnings("unchecked") cloneBoard = (B) board.clone();
In the Sun annotation tutorial, I did not find an answer to why this is: http://docs.oracle.com/javase/tutorial/java/javaOO/annotations.html .
The grammar definition didn’t help me either, since I’m not quite sure that I understand correctly: http://java.sun.com/docs/books/jls/third_edition/html/syntax.html#18.1
It seems to me that the problem is that annotations can be specifically used for variables, but only when they are declared; annotations will not be covered by any subsequent assignment. It's right? Is there a more elegant solution than suppressing unverified warnings for the whole method?
source share