Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implements 接口后,sm 能查询到2个方法 #2791

Open
1 task done
gMan1990 opened this issue Jan 30, 2024 · 1 comment
Open
1 task done

implements 接口后,sm 能查询到2个方法 #2791

gMan1990 opened this issue Jan 30, 2024 · 1 comment

Comments

@gMan1990
Copy link

gMan1990 commented Jan 30, 2024

  • 我已经在 issues 里搜索,没有重复的issue。

环境信息

  • arthas-boot version: 3.6.2
  • version 3.6.2
  • 操作系统版本: Alpine Linux v3.14
  • 目标进程的JVM版本: openjdk 17

重现问题的步骤

step1

public interface RocketMQListener<T> {
    void onMessage(T message);
}

step2

public class StringRocketMQListener implements RocketMQListener<String> {
    @Override
    public void onMessage(String s) {
    }
}

step3

# https://arthas.aliyun.com/doc/sm.html
sm StringRocketMQListener onMessage

期望的结果

输出了2个onMessage

实际运行的结果

难道不是应该1个嘛?

@sirius19
Copy link

sirius19 commented Feb 1, 2024

本质上底层是clazz.getDeclaredMethods()。方法的签名由方法的名称和参数类型决定。
当一个类继承自一个泛型接口或继承自一个带有泛型参数的类时,由于类型擦除的原因,编译器会在字节码中生成桥接方法以保持多态性。可以使用method.isBridge()判断是否桥接方法
上面的代码会有两个 onMessage 方法的签名,一个是接口中声明的 onMessage(T message),另一个是实际实现的 onMessage(String message)

官方文档参考:https://docs.oracle.com/javase/tutorial/java/generics/bridgeMethods.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants