2012-01-31 53 views
1

我現在有一個使用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()); 
} 

這是正確的方式告訴吉斯匹配什麼?或者我使用API​​錯誤?

在此先感謝!

回答

2

這是不是更簡單?:

public void configure(Binder binder) { 

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

} 
+0

是啊!總是很高興有一個全新的視角! – IAmYourFaja 2012-01-31 15:49:12