zoukankan      html  css  js  c++  java
  • Java Annotations

    Java 的 annotation

    • 以@开头 比如@Override. 
    • 不改变complied program的action
    • annotation不完全是comments 能够改变一段代码compile的方式

    下面这段代码因为base class里没有display(int x), 所以是用@Override就会报错。

    /* Java program to demonstrate that annotations are
       not barely comments (This program throws compiler
       error because we have mentioned override, but not
       overridden, we haver overloaded display) */
    class Base
    {
         public void display()
         {
             System.out.println("Base display()");
         }
    }
    class Derived extends Base
    {
         @Override
         public void display(int x)
         {
             System.out.println("Derived display(int )");
         }
     
         public static void main(String args[])
         {
             Derived obj = new Derived();
             obj.display();
         }
    }
  • 相关阅读:
    Investment
    The Fewest Coins
    Bone Collector II
    Cow Exhibition
    饭卡
    A + B Problem II
    F
    敌兵布阵
    单例模式
    面向对象
  • 原文地址:https://www.cnblogs.com/Dylan-Java-NYC/p/4824985.html
Copyright © 2011-2022 走看看