Java自定义注释创建

时间:2020-03-16 14:02:13

标签: java annotations

我想创建自定义注释,以修剪字符串的值。我已经尝试过下面的代码。

主类(存在主方法的地方):

public class App {
    public static void main(String[] args) {

        @Anno(removeSpace = "aaa")
        String a = "   p   ";

        System.err.println(a);

    }
}

自定义注释:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.LOCAL_VARIABLE)
public @interface Anno {

    String removeSpace() default "";

    //I want to write code here but how ??

}

我已经看过堆栈溢出的结果,但是不明白。

0 个答案:

没有答案