When polimorphism is not what you desire

Suppose you have the following program:
class A
     public void methodA()
          System.out.println("A.methodA()");
     public void callMethodA()
          System.out.println("A.callMethodA()");
          methodA();
class B extends A
     public void methodA()
          System.out.println("B.methodA()");
     public void callMethodA()
          System.out.println("B.callMethodA()");
          super.callMethodA();
public class Test
     public static void Go()
          B b = new B();
          b.callMethodA();
}What is the output after you run Test.Go()? Yes, you guessed it right (didn't you?):
B.callMethodA()
A.callMethodA()
B.methodA()
This is a consequence of all methods being polimorphic ("virtual" in C++ jargon) by default in Java. I ran into a situation today in which I needed that the output was
B.callMethodA()
A.callMethodA()
B.methodA()
This is, that invoking super.callMethodA() from an instance of B (or from any descendant of A) would call A's methodA(), not B's methodA(). Sadly, there doesn't seem to be any way to prevent that a method behaves polimorphically. My solution was to rename A.methodA() as A.aMethodA() and qualify it as "final" and then make A.callMethodA() calls A.aMethodA().
Thoughts?

McCormick wrote:
Well, B's methodA() is a useful method so I can't remove it. Indeed, the solution of renaming A.methodA() could have been instead "rename B.methodA()". My point was that I ran into a situation where I didn't want/expect a polimorphic behavior but that's what I got. Since Java doesn't provide any other way to prevent pholimorphism (compared to C++/C# where you may not qualify a method as "virtual"), you have to use "final" to avoid it.
Thoughts?Yes, don't think like a C++ programmer.
class A {
     private void methodAHelper()     {
          System.out.println("A.methodA()");
     public void methodA()     {
          methodAHelper();
     public void callMethodA() {
          System.out.println("A.callMethodA()");
          methodAHelper();
class B extends A {
     public void methodA() {
          System.out.println("B.methodA()");
     public void callMethodA() {
          System.out.println("B.callMethodA()");
          super.callMethodA();
public class Test {
     public static void Go() {
          B b = new B();
          b.callMethodA();
}and no final keywords.
Winston

Similar Messages

  • Search engine widgets have go daddy "cheep" page and yahoo search come up when using widget not what you type in.

    When working with search engine widgets, press enter after making entry and you are sent to "cheepa.com" page brought to you by godaddy. Also seach is by yahoo search. How do you get rid of this page.

    Some toolbars will change the usual Firefox search, but they would usually be consistent in steering you to the same site.
    Your PC may have contracted some malware. You can supplement your regular security software with these two highly regarded scanners:
    Malwarebytes Anti-malware : http://www.malwarebytes.org/mbam.php
    SUPERAntiSpyware : http://www.superantispyware.com/
    Find anything? Some additional clean-up might be required in Firefox settings as well.

  • Smartforms - What you see is not what you get ?

    I create a delivery note by smartforms.
    Print Preview in the PC, the position of data is correct.
    But printed on the paper, what you see in the PC is not what you get? The page format is custom, not standard.
    Is there somebody know reason?
    Thanks!!

    I all really depends  on the printer, the print drivers, and how the printer is setup on the basis side.
    I have seen the same thing when printing one layout from two different printers.  They didn't look the same.
    Regards,
    Rich Heilman

  • Photo booth mirror-not what you think

    when i use the mirror effect on photo booth, it mirrors the left side of the view (you have two left hands) is there anyway to get it to mirror your right side?

    Hello again, mr.merino
    Another idea that may be of interest to you...
    If you are only trying to make one (or a few) of the reverse mirror images you post about, and if you are not interested in learning and writing Quartz compositions, you can take the "easy" approach and use a mirror.
    Here is how I did what you ask about in Photo Booth without programming. No "Edit > Flip Photo" menu item was applied in any of the following images.
    (1) As a reference, I show this normal Photo Booth image of a left hand pointing left.
    (2) This image uses the "Mirror" effect on the same hand pointing the same way.
    (3) To mirror the right side instead of the left side, I selected the Photo Booth "Mirror" effect to make another mirror image. However, this time, I placed a mirror in front of the iSight and positioned the hand behind the iSight. By adjusting the positions of the mirror and the subject (hand) while I watched in the Photo Booth viewing window, I was able to obtain this image.
    We await your response. Please confirm that the kind of left/right reversal between items (2) and (3) is what you are trying to accomplish.
    EZ Jim
    Mac Pro Quad Core (Early 2009) 2.93Ghz w/Mac OS X (10.6.4)  MacBook Pro (13 inch, Mid 2009) 2.26GHz (10.6.4)
    LED Cinema Display  G4 PowerBook  1.67GHz (10.4.11)  iBookSE 366MHz (10.3.9)  External iSight

  • LR4.2 printing multiple cell with overlap -  What you see IS NOT what you get ?

    Hi,
    I am using LR4.2 and PS-elements. Epson 3800 for printing
    PS - never an isue.
    user is admin ..
    I get a strange phenomena in LR4.2 when doing multiple cells on same print - with overlapping: At time what you see is not what's going to be printed! at times you will get the printout with some of the cells mising photos (even printing them to file will result in the same way..). Post the printing (ouch wasting of paper...) if I select the cell, I can "send it to the front, ad now it will be printed ok/.
    Please advice - did you see this before >?
    Ami

    I have never tried printing overlapping photos.  Can you describe how to a simple photo layout that demonstrates the problem so others can try?  Or at least include a screen-capture of the layout that is showing the issue.  It may have something to do with your particular printer driver even if you print to a JPG, but if others, with other printers have the same issue, then it is likely something within LR, only.

  • AUDIO: What You Hear Is NOT What You Get

    hi guys. i have seen this problem being reported on numerous occasions on this forum, but can't remember if it's really been tackled and solved.
    It may seem the question audio-related and should have been posted in another thread, but i do tend to think it's macbook-related for some reason.
    you see i've worked for ages on ibooks and powerbooks and whatever sound i'd hear through my headphones in any audio-production programme, exactly the same sound would be exported as mixdown.
    now that i've added a macbook to my gear, what i hear during mix, mastering, etc. is NOT what i get on export! my exported material is full of clipping and distortion.
    yes, i know that those "reds" on mixer channels are supposed to mean peaking and that should be avoided. but why is it that i don't hear distortion through headphones/monitors when i see red while my exported audio is distorted?
    as opposed to that, when working on my powerbook g4:
    red = clipping and distortion in any DAW = clipping and distortion in exported audio
    whereas, once again, on a macbook:
    red = most clear sound in any DAW = clipping and distortion in exported audio.
    any thoughts? please! could this be a common macbook / onboard soundcard problem?

    pardon,I'm a little confused... Scenario:Not using cycle record. One track for a lead vocal.I puch in vocal phrases.Is there a technique for going back to earlier pass takes and lock a take in the arrange window if I want to ?Why create duplicate tracks?I do not want to create extra tracks,want the lead vocal to be on it's own single track that has punches.I usually only want the most recent punch as I move on after a good take.In this current song I rewind happy to hear my performance but I end up seeing it(the punch)but hearing and underlying take ??? Why. PLease elaborate. Thanks ~
    G5 Dual 2.7   Mac OS X (10.4.3)  

  • What You Hear Is NOT What You Get

    (previously posted on another thread. never got an answer to this, though.)
    hi guys. i have seen this problem being reported on numerous occasions on this forum, but can't remember if it's really been tackled and solved.
    It may seem the question audio-related and should have been posted in another thread, but i do tend to think it's macbook-related for some reason.
    you see i've worked for ages on ibooks and powerbooks and whatever sound i'd hear through my headphones in any audio-production programme, exactly the same sound would be exported as mixdown.
    now that i've added a macbook to my gear, what i hear during mix, mastering, etc. is NOT what i get on export! my exported material is full of clipping and distortion.
    yes, i know that those "reds" on mixer channels are supposed to mean peaking and that should be avoided. but why is it that i don't hear distortion through headphones when i see red while my exported audio is distorted?
    as opposed to that, when working on my powerbook:
    red = clipping and distortion in any DAW = clipping and distortion in exported audio
    whereas, once again, on a macbook:
    red = most clear sound in any DAW = clipping and distortion in exported audio.
    any thoughts? please! could this be a common mabook / onboard soundcard problem?

    Whatever answer will be given: Use a Limiter when doing a mixdown and exporting. Going over 0db is never a good idea with digital equipment.
    Fox

  • Inactive pixels, but its not what you think.......

    Just purchased a 5800 Xpress direct from nokia a week ago and have now discovered 3 clusters of inactive pixels comprising of 6, 8, and 10 groups. They are all on the number 1, when in text mode. Now most people, including myself would automatically think hardware fault, however, if I turn to landscape mode the faulty pixels remain on the number 1 position, even though the 1 is at the other side of the screen therefore, in my humble opinion this would point towards a software problem. Has anyone else encountered this strange situation?

    dawndriver wrote:
    There's a chance I could qualify for a wally of the year award. Having looked closely at these pixels perhaps they are meant to be there as symbols.   Perhaps someone could clarify this. When you are about to write a new text message using predictive text, are there 3 marks to the right of the number one?
    Why don´t you take a screenshot? Then you can compare the image with what you are actually seeing on the screen and you can post it here so that we can find out if your qualified for the wally of the year award...  
    http://www.allaboutsymbian.com/How_to_take_screenshots 
    Message Edited by illinjah on 30-Nov-2009 06:52 PM
    Message Edited by illinjah on 30-Nov-2009 06:53 PM
    By clicking the "Kudos!" or the "Solution?" button on the right you can say "Thank You" and you´ll show the author and others that the post is useful.
    The day we stop improving is the day we stop being good.

  • What happen when the wrong download is done and it's not what you choose?

    What do you do when you hve been charged but not recived the order?

    Please explain the circumstances.     You have either bought something you now regret or you have been charged an authorisation fee which will actually never be activated.
    If you bought the Isley brothers by accident, contact Apple via the note on the invoice which invites you to advise them of a problem.  If it is the first occurance of its kind you may find they will clear the charge, but you won't get more than one chance, I'll be bound.

  • CR for VS2010 - font when printing (what you see is not what you get)

    If anyone can help resolve this issue, I would be very grateful!
    We use VS 2010 with the production Crystal Reports for VS 2010.  I deployed a web site to production on a Win 2008 r2 server with IIS 7.
    When the user runs a report (we have it set to be pdf), the font used by the report displays properly.  When printing, it prints with a different font.  The correct font is Old English.  I believe it is printing in arial.
    I installed the font on the server.  I gave rights to the fonts directory for the web site.  I ran the redistributable.  I'm not sure what else to try.

    Yes, I do mean client-side. 
    Also, the crystal report viewer control print mode set to pdf instead of Active X. 
    We had issues with users being able to install the Active X viewer. 
    The font has been installed on the client.
    When you stated "Print Control is via binary page descriptors, where the font composition is turned to printable images on the client-side" ---  Does that mean that certain fonts or even font types may not work?
    Thank you for your help.

  • What You see is not what you get when printing a adobe PDF file

    Hi, we use adobe pdf files to send printing of maps to different customers. Quite often a pdf file looks Ok on the screen but printed on paper some lines is crossing the paper which should not be there.
    It is easy to reproduce and seems to happen on different computers. Most of them use windows7. If we use another program than adobe for displaying and printing the same file the print is correct.
    Is this a bug in print driver or in the Adobe reader which produce the data for the print driver. Most files is created by a thin print solution called UNIPRINT.

    The text spacing also frustrates me, but I'm afraid is a drawback of the iWeb system. I always have to go back and re-tweak certain paragraphs that I try to squeeze into a smaller space. I've learned that it's best to allow for a little breathing room with the width and height of the text field. If the text field is exactly the width and height of your paragraph in iWeb, chances are the lines are going to bump down just a hair, creating an extra line of text which will decrease your line spacing if the height is also tight. Does that make sense?
    As far as the hyperlinks go, I used to get freaked out because what I thought was the wrong formatting, but what I found out was just the formatting for having visited the linked site.
    What iWeb does for those of us who don't know or don't care to mess with html code is an extremely complex process that I can't even begin to understand. And on top of that you add the relative unpredictability of the various browsers and systems that are out there. You have to roll with the punches and figure out these little discrepancies to get the finished product you want.
    Good luck!

  • Footer Issue (not what you think)

    I've spent over an hour now watching video turotirals and reading common issues regarding footers in Adobe Muse.
    My issue is that after I create text, check the footer box as well as the sticky footer box in preferences, and place it below the footer line --  it still doesn't act as a footer. It will remain in the same place despite everything and stay at the bottom of the page. I don't want it be pinned either so it's not an issue there. I'm fairly literate when it comes to adobe software but I can't figure this out. Could it be a weird bug or something on adobe's end? Can anyone help here? Am I doing something totally wrong? Thanks

    On this first screen shot, you can see the text I have set as my footer. You can see that the footer box is checked and it's below the content area.
    This next screen shot is what happens when I drag content down. The text footer doesn't move.

  • Merge to HDR Pro: What you see is not what you get?

    I am using PSCC on an iMac (Mavericks). When I bring bracketed shots into PSCC's Merge to HDR Pro, I can work the settings and/or presets to get an image that looks OK. However, when I exit from HDR Pro by clicking OK, the image displayed in PSCC is very different from what I was just looking at in HDR Pro. The screenshots here show just one example, working in 16-bit mode. Other images show even greater differences. Working in 32-bit mode makes it even worse. This did not use to happen in my earlier versions of PS (perpetual license). Am I missing something or doing something wrong?
    Image in HDR Pro:
    Image in PSCC after clicking OK:

    Trevor.Dennis wrote:
    Yes I realised that.  There are now quite a few applications for processing HDR, and IMO Photomatix has always been the best of them, and certainly did a better job than Photoshop.  My point was that the old 'Merge to HDR Pro' workflow is now redundant if you have Photoshop CC, and that using Camera RAW as outlined by Julianne Kost, has suddenly leapfrogged all the competition by an order of magnitude.
    So I strongly urge you to take Mr Prengel's advice. Output the image in 32bit, and use ACR to process it.  Did you watch the video tutorial I linked to?
    You certainly shouldn't get all pixel-peeper about how the 32bit image looks on your screen.  It is not possible to show the tonal width of a 32 bit image on a computer screen, so you are seeing a 'representation' of how it might look after processing.
    FWIIW I have taught HDR (and Photoshop) to some of the best photographers in the world at two PSNZ National Conventions back in 2010 and 2011, so I kind of have strong opinions about it.  Not that I use it excessively, but it is a very handy tool to keep in your photographic skills repertoire.
    Trevor,
    I am sorry if I misunderstood your post. I am actually using the same workflow as Julianne Kost in her video (which I had watched prior to posting here). And, as I posted above, I do agree with Mr. Prengel that I should just take the 32 bit image into Camera Raw and do the toning there. As a matter of fact, that is what I have been doing in Photoshop CC (sending the pictures from Lightroom, same as Julianne Kosts does), and I can do a very good job, if I say so myself.
    So the question I had was merely one of puzzlement at seeing the difference between the image just before exiting HDR Pro and what shows up in Camera Raw. In the examples I provided, and in many other cases, it clearly went beyond pixel-peeping: they were two very different images. But I think I understand now why this is, which you kindly pointed out: it is not possible to show the tonal width of a 32 bit image on a computer monitor. I had not considered that and I thank you for mentioning it.
    It may be that in some cases (as in Julianne Kosts's video) the representation in HDR Pro is actually pretty close to the initial view in Camera Raw, but in other cases (my examples) it is not. Not really an issue, I agree.

  • July 17 Doc icon - No. It's not what you think...

    I know that you suppose to open iCal for the Doc icon to change to today's date. Everything used to work just fine even after I quitted iCal.
    Now, when I fire iCal the Doc icon changes, but when I quit it goes back to "July 17" instead of keeping todays date. Any ideas?
    TIA

    L i o r,
    Dancin' Brook provides links to explain this frequently observed/maligned iCal behavior in Tiger.
    ese,
    Welcome to Apple Discussions.
    iCal registration is not required.

  • Volume level not what you think

    So I don't have any volume problems when it comes to hearing someone when i'm talking to them on the phone. Or when it comes to listening to music via the speaks or through headphones. What does give me problems is when I'm playing a movie that was purchased from itunes.
    The sound from that movie is pitifully low. I can max out the volume slider and volume button but it's still low as ****. So I don't know if it's a movie issue or a phone issue

    The movie is easy to fix.
    In iTunes, highlight the movie, click Get Info(apple-I), click options, and use the volume adjustment slider. That will change the tag, and give you higher volume. Hope that helps you.

Maybe you are looking for