gpt4 book ai didi

java - 关闭 Google Guice 中的匹配

转载 作者:行者123 更新时间:2023-11-30 04:54:16 25 4
gpt4 key购买 nike

我目前有一个使用以下绑定(bind)的Module impl:

binder.bindInterceptor(Matchers.any(), Matchers.any(),
new WidgetInterceptor());

我希望能够以编程方式打开/关闭此功能,这是我所做的:

private boolean widgetInterceptionEnabled = true;

public void configure(Binder binder) {
Matcher<Object> matcher = null;
if(widgetInterceptionEnabled)
matcher = Matchers.any();
else
matcher = Matchers.not(Matchers.any());

binder.bindInterceptor(Matchers.any(), matcher,
new WidgetInterceptor());
}

这是告诉 Guice 匹配任何内容的正确方法吗?还是我使用的 API 错误?

提前致谢!

最佳答案

这样不是更简单吗?

public void configure(Binder binder) {

if(widgetInterceptionEnabled){
binder.bindInterceptor(Matchers.any(), Matchers.any(),
new WidgetInterceptor());
}

}

关于java - 关闭 Google Guice 中的匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9079522/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com