springcloud| 代码简化lombok

首先我们来看一下,为什么我们使用了lombok注解,我们就能直接使用?

@Slf4j
public class JasyptUtil {
    public static void main(String[] args) {
        log.info("Hello YvesHe!");
    }

}

有点类似语法糖的意思,下面是反编译后的结果


@Slf4j注解的源码

package lombok.extern.slf4j;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface Slf4j {
	/** @return The category of the constructed Logger. By default, it will use the type where the annotation is placed. */
	String topic() default "";
}


package java.lang.annotation;

/**
 * Annotation retention policy.  The constants of this enumerated type
 * describe the various policies for retaining annotations.  They are used
 * in conjunction with the {@link Retention} meta-annotation type to specify
 * how long annotations are to be retained.
 *
 * @author  Joshua Bloch
 * @since 1.5
 */
public enum RetentionPolicy {
    /**
     * Annotations are to be discarded by the compiler.
     */
    SOURCE,

    /**
     * Annotations are to be recorded in the class file by the compiler
     * but need not be retained by the VM at run time.  This is the default
     * behavior.
     */
    CLASS,

    /**
     * Annotations are to be recorded in the class file by the compiler and
     * retained by the VM at run time, so they may be read reflectively.
     *
     * @see java.lang.reflect.AnnotatedElement
     */
    RUNTIME
}


参考: http://blog.didispace.com/java-lombok-1/
参考: https://zhuanlan.zhihu.com/p/32779910 (全)
参考: https://www.cnblogs.com/hollischuang/p/12294100.html

你可能感兴趣的:(spirngcloud)