public class IsolatedClass
{
public static <T> Class<? extends T> isolateClass(Class<T> publicBaseClass, Class<? extends T> implementationClass, Class<?>... additionalClasses)
{
DynamicClassLoader dynamicClassLoader = new DynamicClassLoader(publicBaseClass.getClassLoader());
ImmutableMap.Builder<String, byte[]> builder = ImmutableMap.builder();
builder.put(implementationClass.getName(), getByteCode(implementationClass));
for (Class<?> additionalClass : additionalClasses) {
builder.put(additionalClass.getName(), getByteCode(additionalClass));
}
// load classes into a private class loader
Map<String, Class<?>> isolatedClasses = dynamicClassLoader.defineClasses(builder.build());
Class<?> isolatedClass = isolatedClasses.get(implementationClass.getName());
// verify the isolated class
checkArgument(isolatedClass != null, "Could load class %s", implementationClass.getName());
checkArgument(publicBaseClass.isAssignableFrom(isolatedClass),