标题翻译
Java custom annotation creation
问题
自定义注解,用于修剪字符串的值。我尝试了以下代码。
主类(包含主方法的位置):
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 "";
// 我想在这里编写代码,但是如何实现??
}
我在 Stack Overflow 上查看了结果,但没有理解清楚。
英文翻译
I want to create custom annotation that trims the value of a string. I have tried below code.
Main class (where main method exist):
public class App {
public static void main(String[] args) {
@Anno(removeSpace = "aaa")
String a = " p ";
System.err.println(a);
}
}
Custom annotation:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.LOCAL_VARIABLE)
public @interface Anno {
String removeSpace() default "";
//I want to write code here but how ??
}
I have watched results in stack overflow but did not understood.
专注分享java语言的经验与见解,让所有开发者获益!
评论