java 注解

注解

JDK 5.0 Annotation

注解可以被其他程序读取

内置注解

@Deprecated //不推荐使用 已经被淘汰 或者又更好的方法
@Override  //重写方法
@SuppressWarnings() //镇压警告 有参数

元注解

复制解释其他注解的注解 meta-annotation

@Target
@Retention
@Documented
@Inherited
import java.lang.annotation.*;
​
@MyAnnotation
public class Test01 {
    @MyAnnotation
    public void test(){
    }
}
//注解可以表示 我们的注解可以用在什么地方
@Target(value = {ElementType.METHOD,ElementType.TYPE})
@Retention(value = RetentionPolicy.RUNTIME) //什么时候有效 Runtime>Class>Source
@Documented //表示是否我们在注解的生成在JavaDoc中
@Inherited //子类可以继承父类的注解
@interface MyAnnotation{ //@interface 来自定义一个注解
​
}

自定义注解

public class Test03 {
    @MyAnnotation2()
    void  test(){
    }
}
@Target({ElementType.TYPE,ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@interface MyAnnotation2{
    //注解参数: 类型加 + 名字();
    String name() default "";
    int age() default  0;
    int id() default  -1; //默认值-1 表示不存在
    String[] schools() default {"A","B"};
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值