小编Rod*_*yas的帖子

查找字符串中的所有可能的子字符串.Python正则表达式

我想在字符串中找到所有可能的子字符串,其中包含以下要求:子字符串以N开头,下一个字母是除P以外的任何字母,下一个字母是S或T

有了测试字符串"NNSTL",我想得到结果"NNS" and "NST"

这可能与正则表达式?

python regex string

5
推荐指数
1
解决办法
1098
查看次数

Java CDI.Interceptor仅在类的第一个方法调用中调用

我正在使用CDI拦截器,我意识到只有在使用@Interceptor注释的类中的第一个方法调用才会被截获.在下面的示例中,方法B从未被截获.

@InterceptorBinding
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Transactional {

}


@Transactional
@Interceptor
public class TransactionsInterceptor {

    @AroundInvoke
    public Object transactionInterceptor(InvocationContext context) throws Exception {

          System.out.println("Method="+context.getMethod().getName());
          return context.proceed();

    }
}


public Interface AnImportantInterface {
      public void methodA();
      public void methodB();
}

@Transactional
@ThreadScoped
public class AnImportantClass implements AnImportantInterface {

    public void methodA() {

        methodB();
    }

    public void methodB() {

        //This method is never intercepted
    }

}


public class AnotherImportantClass {
    @Inject AnImportantInterface aui;

    public void someMethod() {
        aui.methodA();
    }
}
Run Code Online (Sandbox Code Playgroud)

如果首先调用methodA,我怎样才能截获该方法?有一些解决方法吗?

java interceptor cdi

5
推荐指数
1
解决办法
2262
查看次数

Groovy的.是否可以将方法保存到var中?

好吧,我想将一个方法保存到var中以便稍后调用它.我想要这样的东西:

class A {
     def sayHello() {
         "Hello"
     }
}

def a = new A()
def sayHelloMethod = a.sayHello
def result = sayHelloMethod()
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点?

groovy

4
推荐指数
1
解决办法
719
查看次数

标签 统计

cdi ×1

groovy ×1

interceptor ×1

java ×1

python ×1

regex ×1

string ×1