使用仪器更改类的父类

huangapple go评论58阅读模式
英文:

Change parent of the class using instrumentation

问题

I have a class called Client, it is extending Connection class, I want to make a class called KConnection which extends Connection class, and I want that the parent of the Client should not be Connection but it should be KConnection using bytebuddy agent in the premain using AgentBuilder(). something like this

new AgentBuilder.Default()
        .type(ElementMatchers.named("Client"))
        .transform(new AgentBuilder.Transformer() {
          @Override
          public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassLoader classLoader) {
            return builder.superclass(KConnection.class);
          }
        })
        .installOn(inst);

Can anyone guide me over here..?

英文:

I have a class called Client, it is extending Connection class, I want to make a class called KConnection which extends Connection class, and I want that the parent of the Client should not be Connection but it should be KConnection using bytebuddy agent in the premain using AgentBuilder(). something like this

new AgentBuilder.Default()
        .type(ElementMatchers.named(&quot;Client&quot;))
        .transform(new AgentBuilder.Transformer() {
          @Override
          public DynamicType.Builder&lt;?&gt; transform(DynamicType.Builder&lt;?&gt; builder, TypeDescription typeDescription, ClassLoader classLoader) {
            return builder.superclass(KConnection.class);
          }
        })
        .installOn(inst);

Can anyone guide me over here..?

答案1

得分: -1

我已经在Byte Buddy的GitHub问题页面上提出了问题,并且问题已经解决。附上参考链接。

https://github.com/raphw/byte-buddy/issues/1403

英文:

I have reached out to the byte-buddy git hub issues and it was solved. Attaching reference .

https://github.com/raphw/byte-buddy/issues/1403

huangapple
  • 本文由 发表于 2023年2月8日 16:33:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75383095.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定