Ow ow ow ... this.isAbuse()



  • public abstract class AbstractFrame extends JInternalFrame {
    
      public AbstractFrame thisFrame = null;
    
      public void init() {
    
        addInternalFrameListener(new InternalFrameAdapter() {
    
          public void internalFrameClosing(InternalFrameEvent ife) {
            dispose();
            // other stuff to handle the closing event that has since
            // been removed/commented out
          }
        });
    
        thisFrame = this;
      }
    
    
    So, every AbstractFrame (and descendent of AbstractFrame) will have a pointer to itself? I guess the original programmer didn't fully understand the concept of 'this' ... and inheritance ... and polymorphism ... But I could be a bit cynical ...

  • 🚽 Regular

    this.thisFrame.thisFrame.thisFrame.thisFrame.thi...

    Whenever I find gems like this, I look for all references to it just to further entertain myself figuring out why the user thought this was a good idea.



  •  But how can you reference thisFrame otherwise?

     

    What if you were to replace thisFrame with a reference to a different frame?!?



  • @RHuckster said:

    Whenever I find gems like this, I look for all references to it just to further entertain myself figuring out why the user thought this was a good idea.
    As do I ... in this case, they really didn't understand that 'this' wasn't an actual AbstractFrame type in child classes ... so to be sure that they had 'this' descendent type whenever methods were called in AbstractFrame, they used thisFrame instead of this.



  • @BeepDog said:

    But how can you reference thisFrame otherwise?
    What if you were to replace thisFrame with a reference to a different frame?!?
    'thisFrame' is only ever modified in init() ... and set to 'this' ... so ... um ... no? edit: fail quoting 101



  • Aha! They're using 'thisFrame' in anonymous inner-classes that don't have (proper) access to 'this' ... button handlers that 'do stuff' in the inner class instead of calling a method of AbstractFrame or some other handler to do work.

    Bad programmer!  /spank



  •  That's a typical way of accessing outer "this" from inner classes by coders who don't know they can simply write AbstractFrame.this in inner classes ;)



  • Calling AbstractFrame.this is ugly syntax; it makes it look like you are getting a static member of AbstractFrame.


  • 🚽 Regular

    @zelmak said:

    'thisFrame' is only ever modified in init() ... and set to 'this' ... so ... um ... no?
     

    But it's a public property.



  • @Whoa314 said:

    Calling AbstractFrame.this is ugly syntax; it makes it look like you are getting a static member of AbstractFrame.
     

    At least it's better than creating an actual Field.

     

    Speak about ugly syntax:

     

    <font face="terminal,monaco">Outer outerInstance  = new Outer();
    Outer.Inner inner = outerInstance.new Outer.Inner();</font>



  • @tchize said:

    @Whoa314 said:

    Calling AbstractFrame.this is ugly syntax; it makes it look like you are getting a static member of AbstractFrame.
     

    At least it's better than creating an actual Field.

     

    Speak about ugly syntax:

     

    <font face="terminal,monaco">Outer outerInstance  = new Outer();
    Outer.Inner inner = outerInstance.new Outer.Inner();</font>

    So, you were under Oveur and over Unger.



  • @kilroo said:

    @tchize said:

    So, you were under Oveur and over Unger.

     

    So... he was over Uneger and Unger was over Dunn?

     



  • @RichP said:

    @kilroo said:
    @tchize said:

    So, you were under Oveur and over Unger.

    So... he was over Uneger and Unger was over Dunn?

    Not as good as the original!!


Log in to reply