我想在字符串中找到所有可能的子字符串,其中包含以下要求:子字符串以N开头,下一个字母是除P以外的任何字母,下一个字母是S或T
有了测试字符串"NNSTL"
,我想得到结果"NNS" and "NST"
这可能与正则表达式?
我正在使用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,我怎样才能截获该方法?有一些解决方法吗?
好吧,我想将一个方法保存到var中以便稍后调用它.我想要这样的东西:
class A {
def sayHello() {
"Hello"
}
}
def a = new A()
def sayHelloMethod = a.sayHello
def result = sayHelloMethod()
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?