lombok 实验性注解之 @StandardException

最全的 lombok 注解详情(随着版本不定时更新)

一、注解介绍

定义异常类,它会最多生成四个构造函数:无参、消息、异常、消息 + 异常,当你手写其中的构造函数后注解将不会重复生成

二、属性介绍

  • access:定义构造函数的访问修饰符
    共有 PUBLIC、MODULE、PROTECTED、PACKAGE、PRIVATE、NONE
    MODULE 是 Java 9 的新特性,NONE 表示不生成 getter 方法,即停用注解功能

三、实战演练

@StandardException(access = AccessLevel.PROTECTED)
public class 孟子义 extends Exception {
    
    }
编译后
public class 孟子义 extends Exception {
    
    
  	protected 孟子义() {
    
    
    	this(null, null);
  	} 
  	
  	protected 孟子义(String message) {
    
    
  		this(message, null);
  	} 
  	
  	protected 孟子义(Throwable cause) {
    
    
  		this((cause != null) ? cause.getMessage() : null, cause);
  	}
  	
  	protected 孟子义(String message, Throwable cause) {
    
    
  		super(message);
  		if (cause == null) return;
  		super.initCause(cause);
  	}
}

四、温馨提示

有个奇葩现象,本地调用显示报错,也运行不了,但是能打包成功还能反编译出来
孟子义
孟子义

猜你喜欢

转载自blog.csdn.net/qq_39249094/article/details/121626664
今日推荐