멋져요 Category 클래스의 메소드의 별명 방법 : NumberHelper
내가 클래스를 생성
는 방법이 있습니다 roll(num)
나는 rollOnce
로, 같은 그것을 별명을 원하는, 그래서 내가 쓴 :
static def rollOnce = NumberHelper.&roll
rollOnce
을 호출하면 프로그램이 예외를 throw합니다. 그루비에서 어떻게하는가?
더 많은 세부 사항 :
첫째, 우리는 자바
def userBuildScript = findScript(name) as Closure
use (NumberHelper, StringHelper, UserHelper){
// first make the user object
// then
userBuildScript.call(preBuildUser, businessNumberObject)
}
에, 우리 자신의 사업을 위해 번호를 구현하고 우리가 우리의 Number 클래스에 대한 카테고리 클래스를 작성, 그것은 위의 NumberHelper입니다.
및 빌드 스크립트에서
:user(someRole) { user, number ->
it.someProperty = number.roll() // here, an exception throw
}
groovy.lang.MissingMethodException: No signature of method: xxx.xx.x.user.biz.Number,roll() is applicable for argument types
나에게 이유를 찾을 수 있도록 충분히 이러한 정보입니까?
그리고 답변을 주셔서 감사합니다, 감사합니다 :)
예외 스택 추적을 추가 할 수 있습니까? 그리고 소스 코드도 도움이 될 것입니다. – aldrin
어디서/rollOnce를 어떻게 정의하고 있습니까? 'roll'이 정적이고'rollOnce'에 대한'static' 키워드를 제거하면 잘 동작합니다 - 더 많은 문맥이 필요합니다. –