Results 1 to 5 of 5

Thread: What is SuppressWarnings method in java?

  1. #1
    Join Date
    Nov 2009
    Posts
    131

    What is SuppressWarnings method in java?

    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.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: What is SuppressWarnings method in java?

    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);
       }
    }

  3. #3
    Join Date
    Nov 2005
    Posts
    1,323

    Re: What is SuppressWarnings method in java?

    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.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: What is SuppressWarnings method in java?

    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;
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,389

    Re: What is SuppressWarnings method in java?

    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();
     }

Similar Threads

  1. The eval() method in Java
    By Isabella in forum Software Development
    Replies: 6
    Last Post: 11-08-2010, 05:05 PM
  2. Method replaceAll in java
    By TechGate in forum Software Development
    Replies: 5
    Last Post: 24-02-2010, 01:06 AM
  3. What is method overriding and method overloading in java
    By beelow in forum Software Development
    Replies: 3
    Last Post: 17-11-2009, 08:20 AM
  4. Problem with my java method
    By manjava in forum Software Development
    Replies: 3
    Last Post: 17-11-2009, 06:15 AM
  5. Java: How can I call one method in another method?
    By biohazard 76 in forum Software Development
    Replies: 3
    Last Post: 16-07-2009, 07:12 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,717,979.26084 seconds with 17 queries