1 Reply Latest reply on Jul 1, 2009 6:06 PM by 800387

    Validation with custom annotation


      here is my code:
      public @interface SomeAnnotation {
        public int number() default -1;
      and here is method for what i need this annotation :
        public int calcSomething(int number) {
                     throw new IllegalArgumentException(Constants.NEGATIVE_NUMBER_ERROR);
                return number;
      can anyone tell me how to do so that the validation would be with this annotation and i wont have to throw exception and/or chek if number is negative or not how to use custom annotation for this ? Is this possible? If yes please show me how to do it
        • 1. Re: Validation with custom annotation
          I'm not clear what you are trying to accomplish here. If you want to validate the data coming in, you can use an existing validator framework (such as Spring Modules or Struts Validator) which already has annotations that you can use. If you instead want to check preconditions before a method is fired, you can consider AOP or design by contract API's.

          - Saish