Java Annotations Learning (i) Preliminary understanding and simple use

Source: Internet
Author: User

Objective

  The blog has been open for several years, always do not know what to write. Recently changed job interview, found that they have a lot of things will be used but can not say, because they do not summarize. So write a blog to record what you're going to do, and review it when you are free.

First, annotations

Annotations are new features added after jdk1.5, which can be understood as an identity that can be used in classes, methods, properties ... And so on, then we can handle the class that has the special identity.

jdk1.5 comes with 3 annotations, and you can customize annotations, and now common open source frameworks (Spring, struts2, MyBatis) also support annotation development.

Two, Java comes with three kinds of annotations

  1. < Span style= "color: #000000;" > @SuppressWarnings   Suppress warnings, ignore warnings, tell the compiler with this identity: I want to write this, don't give me a warning!
     public   Class   Test { //  Remove the warning  @SuppressWarnings ("unused"   static  void   main (string[] args) { //  This would warn: the variable is not used  List List = new  arraylist<string> (    ); }}
  2. @Deprecated used to mark a method obsolete
     /**   * @Deprecat Ed This method is obsolete, use the new Method xx ()  */  @Deprecated public  void   SayHello () {System.out.println (" This method is obsolete!)    "); }
  3. @Override means to overwrite the method, and in eclipse if it is wrong, there will be an error message.
    Interface testinterface{    void  SayHello ();} class Implements testinterface{    @Override    publicvoid  SayHello () {        System.out.println ("method overrides");}    }

Java Annotations Learning (i) Preliminary understanding and simple use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.