1 Reply Latest reply on Dec 8, 2009 12:42 AM by Tim Evers

    Inherit @Observer annotation

    Michael Hunziker Newbie

      Dear all!


      I'm a Java newbie and I'd really appreciate some help:


      I just created a base class which defines the event handling method doSomething with the observer annotation someEvent.


      Am I right that if I wanted to create a sub class and overwrite the doSomething method I would have to redeclare the @Observer annotation? Is there a way to inherit observer annotations?


      Thank you for your help!
      Michael

        • 1. Re: Inherit @Observer annotation
          Tim Evers Master

          Well, of course the really easy way to do this is like this:


          In your superclass you have this (NOTE: This code is NOT compiled or checked just typed straight out of my head early in the morning :P)


          public abstract class superAbstractObserverClass {
              abstract void observeMethod();
          
              @Observer("booyah")
              public void observerBooyah() {
                  observeMethod();
              }
          }
          



          So, now all implementations of superAbstractObserverClass have to implement the observerMethod.


          There's probably much better ways of doing this but... best I could come up with at the moment :P


          Oh, and this is not tested so I'm not even 100% sure that it works... but it should :P