Sure, here is the translation: Java自定义注解创建

huangapple 未分类评论46阅读模式
标题翻译

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.

huangapple
  • 本文由 发表于 2020年3月16日 22:02:13
  • 转载请务必保留本文链接:https://java.coder-hub.com/60707405.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定