Sunday 29 June 2014

@Deprecated

A program element annotated @Deprecated is one that programmers are discouraged from using, typically because it is dangerous, or because a better alternative exists.

A Java compiler produce a deprecation warning when a type, method, field, or constructor whose declaration is annotated with @Deprecated is used.

import java.util.*;

public class DeprecatedEx{    
 
 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 throws below warning.  
Note: DeprecatedEx.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

Since program used the deprecated String Constructor.

You can suppress the compiler warnings by @SuppressWarnings Annotation.

1. Use of the @Deprecated annotation on a local variable declaration or on a parameter declaration has no effect.



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment