首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >AspectJ不匹配类型警告:如何解释?

AspectJ不匹配类型警告:如何解释?
EN

Stack Overflow用户
提问于 2014-10-13 03:57:56
回答 1查看 829关注 0票数 3

我的目标是“围绕”一个类型的子类的所有equals方法。所以,我写了以下方面。

我使用了aspectj-maven-plugin,并告诉它将代码编织到一个依赖jar文件中,因为那是所有equals方法所在的位置。

我得到的奖励是:

代码语言:javascript
运行
复制
Warning:(22, 0) ajc: does not match because declaring type is java.lang.Object, if match desired use target(com.basistech.rosette.dm.BaseAttribute+) [Xlint:unmatchedSuperTypeInCall] 
Warning:(22, 0) ajc: advice defined in com.basistech.rosette.dm.AdmEquals has not been applied [Xlint:adviceDidNotMatch]

我很困惑。BaseAttribute的层次结构中有很多类型都声明了equals,所以它不应该关注Object。添加&&target(BaseAttribute+)似乎并不能消除这个错误。

我遗漏了什么,和/或我应该如何追踪它?

代码语言:javascript
运行
复制
package com.basistech.rosette.dm;

/**
 * See if we can't make an aspect to spy on equals ...
 */
public aspect AdmEquals {
    // we would like to narrow this to subclasses ...
    boolean around(Object other): call(public boolean BaseAttribute+.equals(java.lang.Object)) && args(other) {
        boolean result = proceed(other);
        if (!result) {
            System.out.println(this);
            System.out.println(other);
            System.out.println(result);
        }
        return true;
    }
}
EN

回答 1

Stack Overflow用户

发布于 2014-10-13 04:09:48

好了,天亮了。AspectJ调用规范描述了在类层次结构的基础上定义方法的位置,而不是方法被覆盖的位置。因此,下面的代码声称要做必要的脏活。

代码语言:javascript
运行
复制
public aspect AdmEquals {
    // we would like to narrow this to subclasses ...
    boolean around(Object other) : 
        call(public boolean Object.equals(java.lang.Object)) &&
        args(other) &&
        target(BaseAttribute+)
    {
        boolean result = proceed(other);
        if (!result) {
            System.out.println(this);
            System.out.println(other);
            System.out.println(result);
        }
        return true;
    }
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26329373

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档