Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
761 views
in Technique[技术] by (71.8m points)

java注解的使用 问题

package com.company;
import java.lang.annotation.Inherited;
@Inherited
@interface css {
      String a();
      String b();
      String cd="ss";
}
@css(a = "", b = "")
public class unique implements css{
    @Override
 public String a() {
        return null;
    }
    @Override
 public String b() {
        return null;
    }
    @Override
 public Class<? extends Annotation> annotationType() {
        return null;
    }
}

上面我申明了一个接口注解,并且有两个方法,我这样用哪个注解的接口方法对吗?然后我怎么使用这个接口注解的 String cd="ss"; 呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

注解是类的元数据,用来对类,方法进行描述,说明。要使用注解,可以通过反射获取类信息,拿到类的注解信息就可以使用了。注解是对类,方法的描述,你懂的


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...