Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Eclipse is giving me a warning of the following form: Type safety: Unchecked cast from Object to HashMap<String, String> This is from a call to an API that I have no control over which returns Object: HashMap<String, String> getItems(javax.servlet.http.HttpSession session) { HashMap<String, String> theHash = (HashMap<String, String>)session.getAttribute("attributeK...
Sometime when looking through code, I see many methods specify an annotation: @SuppressWarnings("unchecked") What does this mean?
FindBugs has found a potential bug in my code. But it is not a bug. Is it possible to mark this occurrence as 'not a bug' AND have it removed from the bug list? I have documented quite clearly why for each case it is not a bug. For example. A class implements the comparable interface. it has the compareTo method. I have however not overridden the equals method. FindBugs does not like this a...
I was wondering if scala had an equivalent to java's @SuppressWarnings that can be applied to a function or whatever to ignore any deprecation warnings[1] that function emits? 1: Relevant warning in my case is: method stop in class Thread is deprecated: see corresponding Javadoc for more information. I am aware of the problems with stop however there are still some cases where due to legacy co...
When I compile, javac outputs: Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details.` I wish to suppress this warning. Trying -Xlint:none does not seem to help
I try to get my code to compile with no errors and no warnings as standard practice. There is one annoying warning, though, that I know how to deal with in .NET but not in Java. Say I have a code block like this: try { FileInputStream in = new FileInputStream(filename); return new Scanner(in).useDelimiter("\\A").next(); } catch (FileNotFoundException ex) { LOG...
We are always taught to make sure we use a break in switch statements to avoid fall-through. The Java compiler warns about these situations to help us not make trivial (but drastic) errors. I have, however, used case fall-through as a feature (we don't have to get into it here, but it provides a very elegant solution). However the compiler spits out massive amounts of warnings that may obsc...
Netbeans provides a lot of custom "hints", which are like warnings, only that most of them can't be suppressed (just disabled IDE-globally). But now I looking at code which uses @SuppressWarnings("element-type-mismatch") to suppress a hint/warning which is called "suspicious method call" (such as remove(...) for a collection with a "wrong" type). Well, I would never come to the idea to sup...
In my Eclipse project are a handful of generated .java files that I need to use for SQLJ and I can't move to a separate project (due to Administrative Overhead). These files are also regularly regenerated so editing them is unfortunately out. Unfortunately these files generate a few hundred java compiler warnings which drown out the useful warnings I get on files that I actually can edit. Is...
I have the following code: public abstract class A<T extends B<? extends A<T>>>{ @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; A other = (A) obj; // warning here: "A is a raw type" // ...
i have the following line of code which displays the following warning: HashMap<String,String> currentItem = (HashMap<String,String>) adapter.getItemAtPosition(position); // Warning: Type Safety: Unckecked cast from Object to HashMap <String,String> How can i get rid of this warning?
As part of my Utils class, i have both public static boolean isStringEmptyOrNull(String... s) { When testing for a null condition assertTrue(Utils.isStringEmptyOrNull(null)); I get "The argument of type null should explicitly be cast to String[] for the invocation of the varargs method isStringEmptyOrNull(String...) from type Utils. It could alternatively be cast to String for a varargs i...
It is possible to hide the warning messages in java?
Try to write: List<Object> list; @SuppressWarnings("unchecked") list = (List<Object>) new Object(); It will fail on the 3rd line, on the word list, with the following: list cannot be resolved to a type I understand that it is related to how annotations work. Anybody knows the reasoning behind this? EDIT: thanks for the fast answer. I knew it'd work if the assignment was made a...
 /*
  * Copyright 2004 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Sun designates this
  * particular file as subject to the "Classpath" exception as provided
  * by Sun in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */
package java.lang;
import static java.lang.annotation.ElementType.*;

Indicates that the named compiler warnings should be suppressed in the annotated element (and in all program elements contained in the annotated element). Note that the set of warnings suppressed in a given element is a superset of the warnings suppressed in all containing elements. For example, if you annotate a class to suppress one warning and annotate a method to suppress another, both warnings will be suppressed in the method.

As a matter of style, programmers should always use this annotation on the most deeply nested element where it is effective. If you want to suppress a warning in a particular method, you should annotate that method rather than its class.

Author(s):
Josh Bloch
Since:
1.5
public @interface SuppressWarnings {
    
The set of warnings that are to be suppressed by the compiler in the annotated element. Duplicate names are permitted. The second and successive occurrences of a name are ignored. The presence of unrecognized warning names is not an error: Compilers must ignore any warning names they do not recognize. They are, however, free to emit a warning if an annotation contains an unrecognized warning name.

Compiler vendors should document the warning names they support in conjunction with this annotation type. They are encouraged to cooperate to ensure that the same names work across multiple compilers.

    String[] value();
New to GrepCode? Check out our FAQ X