Hello,
I am last year Computer Science student. In most of the program I have seen many methods specify an annotation:
@SuppressWarnings()
I don't know what is that mean. Can anyone tell me what is SuppressWarnings method in java?
Thank you.
Hello,
I am last year Computer Science student. In most of the program I have seen many methods specify an annotation:
@SuppressWarnings()
I don't know what is that mean. Can anyone tell me what is SuppressWarnings method in java?
Thank you.
Last edited by Juany; 30-01-2010 at 08:40 PM.
The @SuppressWarnings annotation is use when you want to tells the compiler that don't show warning messages which is normally appeared during compilation time. There are various level of SuppressWarnings annotation such as deprecation, uncheckedm, all, fallthrough, serial, path. I have written following program using SuppressWarnings annotation. Just try to understand it.
Code:package ups.common.eg.annotation; import java.util.Date; public class SuppressWarningsEg { @SuppressWarnings(values={"deprecation of SuppressWarnings"}) public static void main(String[] args) { Date dates = new Date(2010, 11, 29); System.out.println("date = " + dates); } }
Hey SuppressWarnings is used to hide warning that is appeared during compile time. Some times we don't want some warning and this time we use @SuppressWarnings annotation. You have to just use following syntax to do this :
@SuppressWarnings("unchecked")
It is very easy to use. Just use this method anywhere in program.
It is very use friendly process. It is used to prevent any warning from appearing during compile time. If want to prevent some warning during compile time then you can use this method. I have written following program for you. Just try to understand it.
Code:public List<Stringss> getALegacyListReverseds() { @SuppressWarnings("uncheckeds") List<Strings> list = (List<Strings>)legacyLibrary.getStringList(); Collections.reverse(lists); return lists; }
SuppressWarnings method is used to Suppress named compiler warnings. You can apply @SuppressWarnings method to local variables, fields, methods, constructors, parameters, and types. If you want to suppress a warning in a particular method, you should annotate that method rather than its class. I have written following program for you just try to understand it.
Code:package java.lang; import java.lang.annotation.*; import java.lang.annotation.ElementType; import static java.lang.annotation.ElementType.*; @Targets({TYPEs, FIELDs, METHODs, PARAMETERs, CONSTRUCTORs, LOCAL_VARIABLEs}) @Retentions(RetentionPolicy.SOURCEs) public @interface SuppressWarningss { String[] values(); }
Bookmarks