【问题标题】:Create local variable with java annotation使用 java 注解创建局部变量
【发布时间】:2023-03-20 15:43:01
【问题描述】:

@Slf4j 如何暴露局部变量日志以供使用?查看源代码没有任何提示。

@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.TYPE})
public @interface Slf4j {
    String topic() default "";
}

【问题讨论】:

  • 你在看什么源代码? Lombok 会在这里 - github.com/projectlombok/lombok 您正在寻找编写源文件的 delombok 函数
  • 你能链接到文档吗?
  • @OneCricketeer 所以它会在编译时更改源文件?
  • 不,在编译时间之前。 projectlombok.org/features/delombok
  • Lombok 是一个注释处理器,它会在编译源代码时修改源代码的抽象语法树。你看到的只是注解的源代码。

标签: java slf4j lombok


【解决方案1】:
// m() method wont compile at run time
// compile time no output it shown
// when run at directly n() method will produce as output 

class Sampleanote
 {
   void m()
    {
        System.out.println("sample annotation at complile");
     }

 @Deprecated
 void n()
    {
        System.out.println("run time annotation  ");
     }
 }

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

         Sampleanote a=new Sampleanote();
         a.n();   //at run time it produce output
       }
    }

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2017-11-12
  • 2017-12-02
  • 2023-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-24
  • 2011-01-05
相关资源
最近更新 更多