Redefine a specific instance with ByteBuddy

I'm quite new to ByteBuddy and may lack some points here.

I want to redefine a specific instance or more precise, instances of a Type that are instantiated in a specific class with ByteBuddy.

So if I have a class A which declares a variable of Type C and a class B which also declares a variable C, I want just to redefine the instance created in A and leave the original implementation in B. (e.g. just redefine objects which passes an equals check / object == object)

I tried the following, which does not work because the equals check goes against a TypeDescription not against the object in the method:

Object myObject = new Object();
    new AgentBuilder.Default()
                    .transform((builder, typeDescription, classLoader, module) ->
                                               //Bind all necessary attributes here                                                

Is there any way to achieve that? I didn't find anything regarding to ElementMatchers.

Read more here:

Content Attribution

This content was originally published by David Witte at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: