4 Replies Latest reply on Jun 6, 2009 1:52 PM by Mike Wilson

    compiler warning on AnnotationLiteral subclass

    Mike Wilson Newbie

      I've used the pattern outlined in section 4.5. Obtaining a Web Bean by programatic lookup of the reference guide for looking up beans that have a parameterized binding type. From the guide:




      PaymentProcessor p =
          manager.getInstanceByType(
              PaymentProcessor.class, 
              new CreditCardBinding() { 
                  public void value() { return paymentType; }
              } 
          );
      




      where the binding class is created like:




      abstract class CreditCardBinding
          extends AnnotationLiteral<CreditCard> 
          implements CreditCard
      {}
      




      It all works fine, but the problem is that I am getting a compiler warning:






      The annotation type CreditCard should not be used as a superinterface for CreditCardBinding



      Can this be mitigated somehow?

        • 2. Re: compiler warning on AnnotationLiteral subclass
          Mike Wilson Newbie

          Right, yes. I did actually figure that one out myself. Though, having a class implement an annotation seems odd, so I can symphathize with the warning and was looking for a cleaner kind of change.


          Rephrasing my question: Do you believe this will be the final solution for this use-case, or are you still investigating alternatives?


          And if this will be the final solution; have you somehow verified that this warning will not become an error in a future JDK?

          • 3. Re: compiler warning on AnnotationLiteral subclass
            Gavin King Master

            Do you believe this will be the final solution for this use-case, or are you still investigating alternatives?

            This is the only possible solution until the Java language adds support for instantiating annotations.



            have you somehow verified that this warning will not become an error in a future JDK?

            Eh? This would be a non-backward compatible change to the language. There has only been one such non-backward compatible change since Java 1.2 (the assert keyword), and that was so amazingly unpopular that everyone at Sun has sworn it will never happen again.

            • 4. Re: compiler warning on AnnotationLiteral subclass
              Mike Wilson Newbie

              Gavin King wrote on Jun 05, 2009 21:54:

              This is the only possible solution until the Java language adds support for instantiating annotations.


              Ok, I meant that maybe you were investigating other ways of specifying annotations that would move the warning-inducing code inside WebBeans. But I see that it's probably hard.



              There has only been one such non-backward compatible change since Java 1.2 (the assert keyword), and that was so amazingly unpopular that everyone at Sun has sworn it will never happen again.


              Right, good. I was thinking of that newer compilers may issue warnings in previously clean code (promoting clean to warning) and drawing conclusions about the possibility of warnings also being promoted to errors. Back in the C days a compiler upgrade could lead to just this ;-)