Dear friends,
I just found (using google) that the annoying "unchecked
cast" compilation warnings can be turned off, by adding an
annotation, @SuppressWarnings("unchecked"), before the
line, method or class which causes the warning.
For instance, the line:
Map<Long, CalorimeterHit> hitMap = (Map<Long,CalorimeterHit>)event.get(collectionName);
causes this warning at compilation time:
-----------------
DebugInfoHitMap.java:31: warning: [unchecked] unchecked cast
found : java.lang.Object
required: java.util.Map<java.lang.Long,org.lcsim.event.CalorimeterHit>
Map<Long, CalorimeterHit> inputHitMap =
(Map<Long,CalorimeterHit>)event.get(m_inputHitMapName);
^
1 warning
------------------
To suppress this warning, try this:
@SuppressWarnings("unchecked") Map<Long, CalorimeterHit> hitMap =
(Map<Long,CalorimeterHit>)event.get(collectionName);
However this does not work if the variable declaration and
assignment are not done at the same line. In such a case,
annotating the whole method works:
@SuppressWarnings("unchecked")
public void process(EventHeader event) {
//... warning would be caused here
}
The whole class can also be annotated.
Another note: I think this annotation requires at least
java version 1.5.0_06.
Now a request: please use this annotation only when there
is no way to fix the warning. Please fix it if possible.
Enjoy,
Guilherme
--
|