我想覆盖我的第三方库类之一正在使用的方法。
public abstract class IndirectClient<C extends Credentials, U extends CommonProfile> extends BaseClient<C, U> {
private LogoutActionBuilder<U> logoutActionBuilder = new NoLogoutActionBuilder<>();
@Override
public final RedirectAction getLogoutAction(final WebContext context, final U currentProfile, final String targetUrl) {
init(context);
return logoutActionBuilder.getLogoutAction(context, currentProfile, targetUrl);
}
}
在我的情况下,实现OidcLogoutActionBuilder
接口的类LogoutActionBuilder
被称为:
public class OidcLogoutActionBuilder<U extends OidcProfile> extends InitializableWebObject implements LogoutActionBuilder<U> {
...
//I'd like to override this method
@Override
public RedirectAction getLogoutAction(final WebContext context, final U currentProfile, final String targetUrl) {
init(context);
}
}
我尝试扩展OidcLogoutActionBuilder
类并覆盖所需的方法:
public class OidcLogoutActionBuilderCustom extends OidcLogoutActionBuilder<OidcProfile> {
...
//Method overriden
@Override
public RedirectAction getLogoutAction(final WebContext context, final OidcProfile currentProfile, final String targetUrl) {
init2(context);
}
}
它不起作用,在运行时getLogoutAction()
仍然调用OidcLogoutActionBuilder
而不是OidcLogoutActionBuilderCustom
。我该怎么做呢?