写这个是为了加深我的印象,我老是忘记super关键字的作用,想必是用得太少了,故此加强一下。
abstract class BaseException extends RuntimeException { private final ErrorCode errorCode; private final transient HashMap<String, Object> data = new HashMap<>(); BaseException(ErrorCode errorCode, Map<String, Object> data) { super(errorCode.getMessage()); this.errorCode = errorCode; if (!ObjectUtils.isEmpty(data)) { this.data.putAll(data); } }
其实 super 也就是对父类对象的一个引用,此处是调用父类对应参数类型的构造方法。当然也可以用过 super 来访问父类的成员变量,
这个太简单了就不一一列举了,反正记得住就行。