Mike Simmons wrote:Right - you can't annotate an arbitrary line of code. But you can annotate a declaration - even a declaration of a local variable.
Like you, I prefer to minimize the scope of @SuppressWarnings, so I usually try to either move the offending code to an existing declaration, or create a new method just for the offending code. For example here's a catch-all for most any casting you may want to do, if you want to completely disregard compile-time checking for that cast:
If you still don't want to suppress warnings for the entire method, a temporary variable will help you out: