byte-buddy

What's the byte buddy equivalent of cglib's Enhancer.isEnhanced?


I'm converting some code from cglib to byte buddy.

The current code has this statement:

if (net.sf.cglib.proxy.Factory.class.isAssignableFrom(entityClass) || net.sf.cglib.proxy.Enhancer.isEnhanced(entityClass)) {
...
}

Does byte buddy have something equivalent?

Can/should I rely on the class name? (I'm using the default naming strategy)


Solution

  • It does not. Cglib implements an interface for all of its proxies. The method basically checks if an instance is of this interface type. You are free to define your own (marker) interface and check for its implementation.

    The disadvantage of cglibs approach is that proxies always need to be loaded by the same class loader as cglib itself. Sometimes, this makes it impossible to use the library.