Thursday, February 19, 2009

How to suppress unchecked warnings in Java




The best way to suppress unchecked or other warnings is to fix the cause of the warning. However in some rare cases, the warning is incorrect and there is no logical way to solve it without compromising the intended functionality. For such cases there is a simple solution:

Add the following just before the method definition:

@SuppressWarnings("unchecked")

This stops any unchecked warnings from the code within the method.

No comments: