java 一個註解不能繼承自另外一個註解!!! java
註解的語法比較簡單,除了@符號的使用以外,它基本與Java固有語法一致。ide
Java SE5內置了三種標準註解:ui
Java還提供了4中註解,專門負責新註解的建立:.net
定義一個註解的方式: code
@Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface Test { }
@Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface UseCase { public String id(); public String description() default "no description"; }
public class PasswordUtils { @UseCase(id = 47, description = "Passwords must contain at least one numeric") public boolean validatePassword(String password) { return (password.matches("\\w*\\d\\w*")); } @UseCase(id = 48) public String encryptPassword(String password) { return new StringBuilder(password).reverse().toString(); } }