🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #8423

Re: Is "return super;" a valid statement

#8423
From: Torsten Welches
Date: Tue, 20 Mar 2001 13:50
56 lines
2565 bytes
"Ralph Quapp" <-> wrote:
>I therefore wanted to 'remove' the B part of the instance. But 
>probably - even when it would be a valid construct - it would 
>not work as it still will behave polymorphic 

yes, there is (for good reason) *no* way to change the runtime-type of an object so you can't "remove" parts. What you can do 
is make use of Java's access control features - your special 
subclass would be, say, a private inner class of your "real" class so nobody else can "use" it. Like this:

public class RealClass {

  public RealClass() {
    //do nothing special
  }

  public static RealClass getNewInstance() {
    return new SpecialClass();
  }

  private static class SpecialClass extends RealClass {

    private SpecialClass() {
      doSpecialThings();
    }

    private void doSpecialThings() {
      System.out.println("this is behind the scenes");
    }
  }
  
}

public class RealClassUser {
  public static void main(String[] args) {
    RealClass aRealClass = RealClass.getNewInstance();
    //show the runtime-type
    System.out.println(aRealClass.getClass().getName());    
    //but nobody else can make use of SpecialClass anyway
  }
}

I am not sure if this is what you are after though ;-)

>The question is now, should the compiler issue some warning or 
>not. 

Your original code is illegal, so the compiler should issue an 
error. 

>I am wondering what kind of bytecode JBuilder generates. 
>How can I see that?

javap -c is for that.

Torsten
Technical Details
Message-ID: <3ab76014$1_1@dnews>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!news.maxwell.syr.edu!nntp1.njy.teleglobe.net!teleglobe.net!hub.org!hub.org!PeerFeed.KWeb.on.ca!dnews!207.105.83.65
References: <3ab26402$1_1@dnews> <MPG.151cdabe37c2b74f98a084@forums.borland.com> <MPG.151df2148cd2b2f398a08a@forums.borland.com> <3ab6816f_1@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,a2b6df84216d25a2
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-03-23 03:54:06 PST
From: "Torsten Welches" <torsten.welches@who.cares.netcologne.de>
Sender: "Torsten Welches" <torsten.welches@who.cares.netcologne.de>
Reply-To: "Torsten Welches" <torsten.welches@who.cares.netcologne.de>
Subject: Re: Is "return super;" a valid statement
Newsgroups: borland.public.jbuilder.java.language
X-User-Info: 193.158.55.74 193.158.55.74    
References: <3ab26402$1_1@dnews> <MPG.151cdabe37c2b74f98a084@forums.borland.com> <MPG.151df2148cd2b2f398a08a@forums.borland.com>  <3ab6816f_1@dnews> 
NNTP-Posting-Host: 207.105.83.65
Message-ID: <3ab76014$1_1@dnews>
Date: 20 Mar 2001 05:50:12 -0800
X-Trace: 20 Mar 2001 05:50:12 -0800, 207.105.83.65
Lines: 56
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!news.maxwell.syr.edu!nntp1.njy.teleglobe.net!teleglobe.net!hub.org!hub.org!PeerFeed.KWeb.on.ca!dnews!207.105.83.65