目录
背景
开发过程中发现一个问题,项目中用Set保存AopMethod对象用于去重,但是发现即使往set中添加相同内容的对象,每次也能够添加成功。
AopMethod类的部分代码如下:
public class AopMethod {
private String methodName;
private Class<?>[] parameterTypes = new Class<?>[]{};
//是否需要忽略掉参数匹配
private boolean ignoreParameterTypes;
public AopMethod() {
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AopMethod aopMethod = (AopMethod) o;
return ignoreParameterTypes == aopMethod.ignoreParameterTypes &&
Objects.equals(methodName, aopMethod.methodName) &&
Arrays.equals(parameterTypes, aopMethod.parameterTypes);
}
@Override
public int hashCode() {
return Objects.hash(methodNa