java中的Annotation和C#中的Attribute相似。

写法上差别较大


@Target(ElementType.METHOD)
@Retention(RetentionPolicy.CLASS)
public @interface MyTag {
    String name();

    int Age();
}

class Testsfd {
    @MyTag(name = "adsf", Age = 12)
    public void info() {

    }
}

同样Annotation也是和Attribute一样,通常要结合反射才能起到比较大的用途。

相关文章:

  • 2021-06-19
  • 2022-01-11
  • 2022-02-08
  • 2021-12-29
  • 2021-09-15
  • 2021-09-23
  • 2021-09-28
  • 2022-03-04
猜你喜欢
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
  • 2022-01-28
  • 2022-12-23
  • 2021-07-23
  • 2022-12-23
相关资源
相似解决方案