Friday 27 June 2014

@SuppressWarnings

It is an annotation to suppress compile warnings that are generated by Compiler. If you want to suppress a warning in a particular method, you should annotate that method rather than its class.

Example
import java.util.*;

public class SuppressEx{    
 
 public static void main(String args[]){
  byte b[] = {1,2,3,4,5};
  String s  = new String(b, 3);
 }
}

When you tries to compile the above program, compiler shows below warnings.

Note: SuppressEx.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

To suppress the warnings change the class file like below.

import java.util.*;

public class SuppressEx{    
 @SuppressWarnings("deprecation")
 public static void main(String args[]){
  byte b[] = {1,2,3,4,5};
  String s  = new String(b, 3);
 }
}

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment