Is this how i'm suppose to use subclasses?

I have this code, and it works, but for it to work, it has to generate exceptions, which I catch, but its weird having a function that in order to work properly always generates exceptions. Is this the way I'm suppose to do this?
               for (FObject i : objects)
                    try
                         FUnit unit = (FUnit)i;
                         unit.moveTowardPoint();
                    }catch(ClassCastException e)
               }objects is an Array of FObjects. FObject is a class with a few functions and protected fields. FUnit is a class that extends FObject and adds the function "moveTowardPoint()" this code works to call moveTowardPoint on all of the FObjects that in objects that are FUnits, but it has to throw exceptions, which I catch.
What I'm trying to ask is, is this type of casting a normal ocurance in Java programming? Does it have any issues, or problems?
Edited by: happypigface on Mar 27, 2008 8:13 PM

You can use the instanceof operator to find out whether the FObject is an FUnit, and only do the cast and method call conditionally. No try/catch required.
But it would be better still if you reworked your code so the caller doesn't need to know what kind of object it has (apart from what would be clear from static type checking, that is, an array or list of FObject).
So maybe you could do:
class FObject {
  void tick() {
    // do stuff common to all FObjects
  // etc
class FUnit {
  void tick() {
    super.tick();
    moveToUnit();
  // etc
}Then your loop is just:
for (FObject i: objects)
  i.tick();

Similar Messages

  • How am I suppose to use my account when the Security questions locking your account and you can't unlock it because you don't have the emails password it sent to

    HOw am I supposed to use iTunes when it just locks my account every time try to buy a song or something

    You need to ask Apple to reset your security questions. To do this, click here and pick a method; if that page doesn't list one for your country or you're unable to call, fill out and submit this form.
    (121740)

  • How am I supposed to use Find My iPhone?

    I do not understand how you are supposed to use Find My iPhone, FROM my iPhone.. it doesn't make sense to me.
    Shouldn't there be a Find My iPhone app on the Macbook?
    Also I have not recieved a verification email for my iCloud Apple ID setup.
    It keeps telling me to "Check Email" yet nothing is there...
    If you could help me with anything, that would be great.
    Thanks..

    you use www.icloud.com to serach for your devices from a mac or any pc via webbrowser.
    or the find my iphone.app to search for your device from your second device/ a friends device.
    If a mac runs 10.7.2 it will also be searchable if  "find my Mac" is activated in icloud preference pane.
    Again, you use any Internet-Cafe or a second PC/Mac to seach your lost devices or Macs.

  • Is this how pacman is supposed to work? (dependency "problem")[SOLVED]

    Hi
    Just did a fresh install of archlinux after buying a new computer.
    Installed some drivers.. kde (and some other stuff)
    Then.. just for the fun of it I removed qt3 with pacman -Rd.
    I was expecting that pacman -Syu would see that a dependency was missing and try to reinstall qt3.
    So I did a pacman -Syu, and what happened? Nothing.. pacman says all is okay, well all is not okay cus kde will not work without qt3.
    Is this how it should work or is this a bug? I checked the manpages for some kind of "install all missing dependencies" but found nothing..
    /Ivan
    Last edited by Fuel (2008-01-23 01:34:22)

    fwojciec wrote:
    That's not how Arch is supposed to work.  Arch is about giving power to the users.  With power comes responsibility, and this responsibility falls on the users in this case.  Remember -- this is a "do it yourself" kind of distribution and so if what I want to do is to screw up my system I should be able to do it in an easy, efficient and elegant way.  This is consistent with the mission statement of the Arch Linux project, this is how Arch works and this is why many of us love it.
    On a personal note, if Arch/pacman tried to hold my hand more, like you suggest it should, I'd be switching to another distro very, very quickly.
    It's not really about trying to get arch/pacman to hold your hand for you. It's more about giving the possibility to recover from a serious mistake. If you can tell me something wrong with adding an option wich checks for missing dependencies on your system and how that particular feature intervenes with "the arch way" - then please do.
    I'm not saying arch is bad, arch is actually the best linux distro I've used so far - but there is something common with almost all distros - you get dependency problems after a while, one way or another.
    Thats why I think there should be a way to resolve such issues.

  • How am I supposed to use my created iCloud contact group on my iPhone?

    I followed the instructions & 'help notes' on creating a contact group by logging into my iCloud account.  Now on my iPhone I can see the group when I go to Contacts & click on the upper left hand "Groups" button, but that screen only lists which list of contacts I've got synced with my iCloud.  Unless I'm missing something, I do not see how I'm supposed to actually use/implement my new "group."  I was hoping to be able to create a new text & type in the name of my group & send, or have an option to choose from a group list to use as my recipients, but instead nothing.
    Am I completely missing the point of grouping contacts on the iPhone???

    About all you can do is when addressing the email, tap the "+", navigate to your groups, uncheck all groups but the group you want to send the email to and tap Done, then tap each member one at a time to add them to the list of recipients.
    Otherwise you can use an app that will allow you to select an entire group at onece (such as Speed Names).

  • It keeps saying that I need to reboot my system from an earlier version but when I reboot my system, there is no change and I to completely remove firefox so I could even get back online, How am I supposed to use your program when it does this?!

    when I upgraded to 4.0 the program states "You must reboot your system to an earlier version" and it locks you out of the internet unless you have another server proxy

    You can check for problems with the <b>places.sqlite</b> database file in the Firefox profile folder.
    *http://kb.mozillazine.org/Bookmarks_history_and_toolbar_buttons_not_working_-_Firefox
    *https://support.mozilla.org/kb/Bookmarks+not+saved#w_fix-the-bookmarks-file
    *Places Maintenance: https://addons.mozilla.org/firefox/addon/places-maintenance/
    You can try to restore the bookmarks from a JSON backup (bookmarks-####-##-##_xxxx_$$$$.json) in the bookmarkbackups folder.
    *http://kb.mozillazine.org/Backing_up_and_restoring_bookmarks_-_Firefox
    *http://kb.mozillazine.org/Lost_bookmarks
    You can try to restore an older copy of the sessionstore.js file via the Time Machine if you use this.
    *http://www.apple.com/support/timemachine/
    *https://support.mozilla.org/kb/Recovering+important+data+from+an+old+profile
    You can use this button to go to the currently used Firefox profile folder:
    *Help > Troubleshooting Information > Profile Directory: Show in Finder

  • Can someone tell me how am I suppose to use my iPad if I have to pay as you go data service which has already cost me $75 for the first month of usage due to not enough GB's usage.

    AT&amp;T and Apple is going to cause people to look elsewhere in order to obtain services to operate their products which might not affect Apple all that much but AT&amp;T may suffer a little bit and apple needs to go ahead provide the means for various ways to connect their devices through AT&amp;T rather than forcing their customers to be locked in to paying an extreme amount of money for service.

    IF you're using more than 2GB per month, you have the wrong device for online service.  It's unclear as to how you are using the iPad.  If you're at home most of the time, you should be using wifi instead.  Much cheaper for extensive data streaming.  If you're instead out and about, knock off the video/audio streaming.
    If you go into System Preferences/Usage/Cellular Usage, it will show you exactly where you are.  I strongly suggest you "zero" out the counter at the start of your monthly data plan and then monitor it from time to time.

  • How am i supposed to use cellular network in ipad mini internationally??

    i am planning in buying an ipad mini with retina display with wifi and cellular function. however i am concerned with its use in Nepal. Is there any method with which i can be able to use a 3G sim card for cellular purpose??

    Hi, nitinfromnpl. 
    Thank you for visiting Apple Support Communities. 
    As long as you purchase the GSM model and acquire a Nano-SIM card, you should be able to use your iPad abroad.  Here is some information about this process that you may find helpful. 
    iPhone and iPad: Using cellular networks while in another country
    http://support.apple.com/kb/ht1807
    Cheers,
    Jason H. 

  • Why isn't there a help (?) icon in my Menu window? how am I supposed to use it to update Firefox???

    There isn't even a greyed out button, if I open with another program which indicates an update is available I get sent to a language selection page. AND I cannot upload a simple gif screenshot to this page!...

    hi Tambran, "help" should be here:

  • When I shut my lid the backlight goes off like it is supposed to, but comes back on after a while. It never used to do this, how can I fix it?

    This problem is a recent one (only has happened in the past 2-3 weeks). When I shut the lid it used to immediately sleep (the power light began to do its fade in and out, and the backlight turned off), but now when I close the lid, the power light stays on, the backlight goes off for a few seconds before coming on again (not sleeping properly?). Then the backlight will turn itself off again and the computer sleeps like it is supposed to. Is something wrong here and how can I fix it?
    Thanks

    I think its the same in 10.5 as in 10.6 (the example below). Do System Preferences > Keyboard. Looks like this:
    UNCHECK the box that reads, "Use all F1, F2, etc, keys as standard function keys," or hold the Fn key to use F11 and F12 for volume control. It looks like you have to own an Apple aluminum keyboard to get a function key on a desktop computer.

  • I've searched to no avail for this problem. Similar posts but none that tell me what to do. I can't add or delete any bookmarks on my iPad 2 running the newest iOS. I know how it's suppose to work, it just isn't working!

    I've searched to no avail for this problem. Similar posts but none that tell me what to do. I can't add or delete any bookmarks on my iPad 2 running the newest iOS. I know how it's suppose to work, it just isn't working!
    It started after the major update to iOS 7.
    I can't believe that this is so hard to do. It's just not letting me. I can add a bookmark to the home screen just fine, just not in a bookmarks folder anywhere I try.
    I've used Apple products since 2001 and have always loved how intuitive they are. But the Safari browser since iOS 7 has been the worst I've experienced. At least right in the beginning after that update.
    I'd really appreciate any help that doesn't just tell me how it's suppose to work...I know that.
    My iPad 4 is not affected with the problem and works as it should.

    To delete, tap "Edit" (tap to enlarge image)

  • This is how I am supposed to contact to have my annual creative cloud membership refunded?  I cancelled immediately upon seeing the charge and followed the instructions given and wound up here.  Am I supposed to share my username and password with the for

    This is how I am supposed to contact to have my annual creative cloud membership refunded?  I cancelled immediately upon seeing the charge and followed the instructions given and wound up here.  Am I supposed to share my username and password with the forum?  Adobe, I am about to go social with my frustrations!

    No, this is a public forum, as in user-to-user, so you should not share any private information here.  You will need to contact Adobe Support by chat or phone, which is apparently getting harder and harder to do.  Use the link below and choose the Still Need Help? option at the bottom in the blue area - in the section that opens take your pick of chat or phone.
    Contact Customer Care

  • I am facing 'How do you want to use this disc' whenever I read/open any lightscribe discs having data.

    Hi,
    When I insert a lightscribe DVD/CD into a lightscribe optical drive, then when I click to open the DVD, I faced this error 'How  do you want to use this disc', although the DVD was full of data. When opening these 
    lightscribe DVD/CD via NON lightscribe optical drive, I noticed that the DVD/CD  opened well without any problems at all.
    Also, how can the System show to me 'How  do you want to use this disc' , in particular when  a DVD is non rewritable(DVD-R) and also contains data)?
    Bear in mind, not all DVDs/CDs were not detected. However, only full lightscribe discs' (having data)
    However, even blank lightscribe discs were detected without problems. When insert a lightscribe disc having data, then I faced that error. However, when inserting  blank lightscribe discs I found that the disc were opened.  Also,
    non lightscribe discs were opened well.
    When checking the device manager, I didn't see any issue with DVD/CD drive. If there were a problem unrecongnising, then I would have seen 'a remarkable mark' in front of it.
    Note: I have faced this problem after trying formating a rewritable CD inserted onto the drive. Althouthg the format failed, all data on the disc was deleted. Anyway, after that, then inserting full-lightscribe  discs are unregonised
    Do you think the problem wth my optical drive. IF so, I would be saying why it wasn't happened with all other non lightscribe discs. If my lightscrib discs were corrupted, then why would they have opened well on another laptop.
    I have done:
    Press the Windows logo key+R to open the Run dialog box.
    Type devmgmt.msc in the Run dialog box, then press Enter. If you are prompted for an administrator password or for a confirmation, type the password, or click Allow
    In Device Manager, expand DVD/CD-ROM drives, right-click the CD and DVD devices, and then clickUninstall.
    When you are prompted to confirm that you want to remove the device, click OK.
    Restart the computer.
    But the same prolbem is existing.
    yes there is a virtual CloneDrive program installed on my PC, however, there is no any CD mounted into it. Even if a CD was mounted into Virtual Clondrive, there would be no problem at all, because the virtual CloneDrive is used to only
      mount ISO disc images into it, and not physical discs.
    Any I have do what you have said, when inserting a light-scribe disc having data, then I open it, I found this
    NOTE: in the above screen shot there is a lightscribe DVD having data inserted. However, in the screen shot below, there  a ightsrbe DVD not having data inserted. In the first screen shot, the disc is not reconginsed by Windows, however, in
    the second is recognised. 
    Even when I have inserted a lightscribe disc not having data(empty), it opened well regardless of  what virutal CloneDrive is enabled or disabled.
    But when cliced on my problem didn't solve,
    A man should convert his anger and sadness into strength to continue living in this life.

    Hi,
    The product Name of my computer is: HP Pavilion dv6-6093ex Entertainment
    Notebook PC support
    The number of my computer is : LM610EA#A2N.
    Could anyone please at this splendid forum take some of their precious time
    out to really reply my questions and solve my problems?
    FIRST OF ALL:
    My HP Pavilion Laptop is about 3 years old.
    My
    sister's Dell Inspiron laptop is 3 years old.
    My HP lapotp is well-cared, as opposed to my sister's Inspiron Dell laptop,
    which is always thrown in dust without caring at all. Also, its battery is
    always inserted even when it is fully charged while the laptop is plugged in to
    the main power supply.
    However, my laptop is either used on only battery, or on plugin. Also, it is
    kept from the dust.
    But, I really found that the battery of the Dell laptop
    still lasts about three and half hours, and there is no problem cooling fan is
    not oproperly preporly.
    I only remember one thing differently done on my laptop battery which is I
    charged it fully, then I stored it without using it for about four months, then
    when I reused it, I found it got worse over time. I.e. first time of using it
    after storing,I found it empty, then I charged it again fully, however, then it
    lasted about 2 hours, then 1 and half hours, next an hour, now it is only
    lasting about 20 minutes without performance. If there is high performance, then
    the computer shuts down suddenly.
    My problem is follows:::
    First: Whenever I inserted any Containing Data OR Data
    CD/DVD-R LightScribe discs, I found that HP optical driver was
    unable to read them. When clicking on the optical disc drive
    'duble-click', then I find that disc opens as this way(NOT: With a CD/DVD player
    is grayed out)
    Blank Or Used CD, DVD±R,RW lightscirbe is unable to be
    read:(clicking on it let it Open like a USB FlashDrive or With a CD,DVD player:
    NOTE: with CD/DVD Player is grayed out)
    Used CD/DVD±R/RW Non-LightScribe disc opens normal:
    Blank CD,DVD±R,RW Non-LightScribe opens normal(Opens like a USB FlashDrive or
    With a CD,DVD)::
    My HP CD/DVD DVD±R/RW specis are::
    Optical Drives
    hp CDDVDW TS-L633R
    Media Type DVD Writer
    Name hp
    CDDVDW TS-L633R
    Availability Running/Full Power
    Capabilities Random
    Access, Supports Writing, Supports Removable Media
    Read capabilities CD-R,
    CD-RW, CD-ROM, DVD-RAM, DVD-ROM, DVD-R, DVD-RW, DVD+R, DVD+RW, DVD-R DL, DVD-RW
    DL, DVD+R DL
    Write capabilities CD-R, CD-RW, DVD-RAM, DVD-R, DVD-RW, DVD+R,
    DVD+RW, DVD-R DL, DVD+R DL
    Config Manager Error Code Device is working
    properly
    Config Manager User Config FALSE
    Drive E:
    Media Loaded
    FALSE
    SCSI Bus 0
    SCSI Logical Unit 0
    SCSI Port 0
    SCSI Target Id
    1
    Status OK
    Trying to solve the problem,
    I have done these steps in order::
    I tried checking with dignostic ulitiy:
    I have tried Advanced View , this is the file of output data
    diagnostic utility
    LightScribe System Software Settings:
    SOFTWARE\LightScribe\MessageDir
    C:\Program Files (x86)\Common
    Files\LightScribe\
    SOFTWARE\LightScribe\LSPrintDialog C:\Program Files
    (x86)\Common
    Files\LightScribe\LSPrintDialog.exe
    SOFTWARE\LightScribe\LSPrintingDialog
    C:\Program Files (x86)\Common
    Files\LightScribe\LSPrintingDialog.exe
    SOFTWARE\LightScribe\LsPrintLauncher
    C:\Program Files (x86)\Common
    Files\LightScribe\LSPrintLauncher.dll
    SOFTWARE\LightScribe\ResourceDir
    C:\Program Files (x86)\Common
    Files\LightScribe\res
    SOFTWARE\LightScribe\LSPrintAPI C:\Program Files
    (x86)\Common
    Files\LightScribe\LSPrintAPI.dll
    SOFTWARE\LightScribe\Update\UpdateShellCommand
    http://www.lightscribe.com/go/downloads/windows
    SOFTWARE\LightScribe\Update\PreviousVersion
    1.18.20.1
    SOFTWARE\LightScribe\Update\CurrentVersion
    1.18.27.10
    SOFTWARE\LightScribe\Update\TrailingVersion
    SYSTEM\CurrentControlSet\Services\LightScribeService\Type
    16
    SYSTEM\CurrentControlSet\Services\LightScribeService\Start
    2
    SYSTEM\CurrentControlSet\Services\LightScribeService\ErrorControl
    0
    SYSTEM\CurrentControlSet\Services\LightScribeService\
    SYSTEM\CurrentControlSet\Services\LightScribeService\DisplayName
    LightScribeService Direct Disc Labeling
    Service
    SYSTEM\CurrentControlSet\Services\LightScribeService\ObjectName
    LocalSystem
    SYSTEM\CurrentControlSet\Services\LightScribeService\Description
    Used by the LightScribe software components to support 3rd party disc labeling
    applications using the LightScribe COM Application Programming Interface
    (LSCAPI). This service needs to run for LightScribe direct disc labeling to
    work.
    SYSTEM\CurrentControlSet\Services\Eventlog\Application\LightScribeService\
    SYSTEM\CurrentControlSet\Services\Eventlog\Application\LightScribeService\
    SYSTEM\CurrentControlSet\Services\Eventlog\Application\LightScribeService\TypesSupported
    7
    SYSTEM\CurrentControlSet\Services\Cdrom\Enum\0
    IDE\CdRomhp_CDDVDW_TS-L633R______________________0300____\4&334f7860&0&0.1.0
    SYSTEM\CurrentControlSet\Services\Cdrom\Enum\Count
    2
    SYSTEM\CurrentControlSet\Services\Cdrom\Enum\NextInstance
    2
    SYSTEM\CurrentControlSet\Services\Cdrom\Enum\1
    SCSI\CdRom&Ven_ELBY&Prod_CLONEDRIVE&Rev_1.4\1&2afd7d61&0&000000
    SOFTWARE\Microsoft\Windows
    NT\CurrentVersion\Winlogon\allocatecdroms
    0
    SYSTEM\CurrentControlSet\Services\CDRom\autorun 1
    SOFTWARE\INTEL\Intel
    Application Accelerator Not detected
    Drives and Media:
    Drive 0 : hp CDDVDW TS-L633R 0300 219 (E, Media
    Imaging Parameter : 114
    I tried running the below command line to fix potential disk issue 'Chkdsk
    /r /f'
    I cleaned the drive, discs, and so on.
    I have uninstalled the all third-party data recording software.
    I have uninstalled the Cyber DVD suite, lightscribe system software which
    came pre-installed with my HP pavilion Notebook.
    I have recovered my system from the Factory Recovery discs.
    I have tried opening all those LightScibe discs not opening on my HP optical
    drive, on a Dell optical drive, and all of them were opened well, although Dell
    optical drive did not have a lightscribe feature at all., nor third party disc
    recording software
    However, the problem is still with opening the discs LIGHT-SCRIBE
    Thus, my questions are:
    How to determine if the drive is corrupted and needs to be replaced with
    another one.
    I think there something needed to be done on the BIOS Of my HP
    laptop[[[A similar problems happened on my Desktop computer's optical
    drive which is as follows:::(ALL discs are opened as empty by Optical Drive of
    My Desktop Computer) ---while my optical drive of my desktop was connected to
    the primary slave IDE, and the HDD was connected to the
    primary master IDE, the optical drive and hard disk are functioning
    well. However, I remember that while burning an image with Nero essential V: 5,
    something went wrong, and then the Optical Drive of My Desktop Computer
    (HL-DT-ST DVD-RAM GH22NP20) became NOT recognised/Installed on
    BIOS, although it was still shown on the device manager as a
    recognised device. Also, it was listed on my computer, however, when entering a
    disc(blank or with data) into the drive, I found it was not recognised, and it
    opened empty(no files at it), although it contains data. Thus, I decided to boot
    to BIOS, and clicked on 'Autodetection for IDE', then I found that only HDD was
    still shown as installed on BIOS. However, the optical drive was not. Th I tried
    clicking on it on BIOS and then clicking on 'enter' to try to let the device be
    re-recognized. However, that made no difference. I had to take part my computer
    ,and then reconnected the optical drive onto the secondary slave
    IDE , and let HDD connected to the same primary master IDE.
    Then, I found that the problem solved and all discs became being read
    normally. Aslo, optical drive became installed on BIOS]]]
    What is meant with with double Layer Support.
    How much does it cost?
    A man should convert his anger and sadness into strength to continue living in this life.

  • TS3988 I changed my Apple ID to my new email address successfully for the iTunes and App store but it won't work for iCloud and it won't recognize my password. I read that this can't be done. How am I supposed to get into iCloud?

    I changed my Apple ID to my new email address successfully for the iTunes and App store but it won't work for iCloud and it won't recognize my password. I read that this can't be done. How am I supposed to get into iCloud? I plan on getting rid of my old email address which is my old Apple ID so how is that going to work?

    Same question Wish someone had replied!
    I changed my Apple ID to my new email and now cannot find any way to access icloud. Unfortunately I had allowed icloud to hijack my airbook files, so of course I am afraid I will lose them tomorrow when I exchange my iphone for a new one and cannot keep an icloud account i cannot access. What a poor sync system! Really atypical for apple!

  • I have a annual plan, it supposed must be used in two terminals, but i haven´t been able to install any app in a second computer, it always says that the app is only available as a trial download. What can I do to solve this issue, and be able to use my p

    I have a annual plan, it supposed must be used in two terminals, but i haven´t been able to install any app in a second computer, it always says that the app is only available as a trial download. What can I do to solve this issue, and be able to use my paid plan in two computers?

    Hi Susan,
    Please refer to the help document to fix this issue:
    Creative Cloud applications unexpectedly revert to trial mode | CS6, CCM
    You may also refer to the thread as below:
    creative cloud software says my free trial has expired, but I have a paid subscription
    Regards,
    Sheena

Maybe you are looking for