The [b]instanceof[/b] operator

Hello again world.
Here's the code in question:
import java.awt.*;
import javax.swing.*;
class InstanceOperator
     public static void main(String args[])
          JButton poo = new JButton();
          if (poo instanceof JComponent)
             System.out.println("It is.");
          else
             System.out.println("It's not.");
}If I change JComponent to Container or Component or Object, I get the string "It is." I am trying to get the string "It's not". However, if I use anything other than something in the JButton ancestral chain - like Window or InstanceOperator - I get the compile error inconvertible types.
I don't understand the usefullness of instanceof if I can only test for direct ancestors. Can anyone explain this with a practical example.
Ciao for now and thanx again one and all.

Demo in code:public class junk{
   public static void main(String[] args) {
        String a = "hello";
        java.awt.Button b  = new java.awt.Button("hello");
        if(checkForType(a).equals("string")) System.out.println("The String has a value of "+a );
        if(checkForType(b).equals("button")) System.out.println("The button has a label of "+b.getLabel() );
   private static String checkForType(Object o){          
       if(o instanceof String) return "string";
       else if(o instanceof java.awt.Button) return "button";
       else return "other object type";
}(and apologies to the OP for my previous mean-ness)

Similar Messages

  • Dynamic equivalent of the Java language CAST operator

    Hello,
    Here is what I want to do:
    I have an Object that contain "something" (I don't know at compilation time). And I want to do this call:
    Object myObject = new String("Hello");
    myMethod (myObject);
    having declared these:
    public void myMethod (Integer dInt);
    public void myMethod (String sString);
    I want the second method to be called. How can I do that?
    I'm looking for something like a dynamic equivalent of the Java language cast operator:
    ??? myMethod ( (myObject.getClass())myObject ); ???
    or ?? myMethod ( (myObject.castTo(myObject.getClass()) ) ; ??
    Thanks.

    How 'bout using the instanceof operator?
    Like this:
    public myMethod(Object obj)
    if (obj instanceof String)
    //do String stuff
    else if (obj instanceof Integer)
    //do Integer stuff
    }

  • Custom exit or badi for changing the user fields in operation of process order

    Hi all
        I want to find a exit or badi to set default value to the user fields in operation of process order when COR1.
        I have tried exit 'PPCO0001', but this exit is call after commit work, so I can not change any thing
        I also tried to use badi 'workorder_update', 'before_update', but all parameters in this BADI are importing, can't be changed, I've tried to change it and then program dump.
        Do you have any solution for this question?
    Thanks

    Do a Implicit Enhancement at the PBO of this subscreen.

  • I updated my IPhone 3GS to the new 5.1 operating system and have since had a range of problems with not only my phone but also my IPad.

    I updated my IPhone 3GS to the new 5.1 operating system and have since had a range of problems with not only my phone but also my IPad.
    Programs (Safari, mail, messages) keep crashing, mail will not delete properly (some will keep popping into my inbox again for no reason!!!), slow, settings lock up etc. etc.
    This only seemed to become an issue once I updated to ios 5.1 and funnily also affected my Ipad even though i hadn't updated the software yet. I have since updated the software on my ipad thinking it might help too but that only made things worse!! So I am not sure if it's an ICloud issue, but when i try to disable ICloud my devices lock up as well.
    The battery life is also shocking!!
    I have hard reset both devices, restored both devices, reset the setting and tried a whole host of other suggestions (like closing background programs) on this forum buit nothing works and i am tearing my hair out.
    I looked in the phone and ipad log and there do seem to be low memory reports though i don't know why these are occuring now when they never have before??
    I don't know if I can restore the old operating system (If I can please let me know how). The phone or ipad are not jailbroken.

    but you should have a backup in itunes.
    Every time you sync your iOS device iTunes creates a backup. go check if its there, iTunes Preferences >Devices. and there you should see if you have a backup, and in case from which date the backup is.
    And ofcourse you can get your icloud data back by just logging in with your Appleid under icloud in settings on the iphone.
    But anyway, if the iPhone works when you restor it as new: try adding your backup, and see if the issue comes back. And experiment with your backup and try to work out what is causing the issue, my guess is that its some app!   Good Luck!

  • The apple store is so unhelpful. I have an iMac computer operating on Mac OSX 10.5.8. I want to upgrade to the latest Mountain Lion operating system so I can work with the iCloud on my computer and download my email. I can't seem to purchase this on-line

    The apple store is so unhelpful. I have an iMac computer operating on Mac OSX 10.5.8. I want to upgrade to the latest Mountain Lion operating system so I can work with the iCloud on my computer and download my emails. I can't seem to purchase this on-line as it keeps telling me to go to the app store. I haven't got the app store on my computer as I am told I need iCloud for which I need the new operating system, which I can't download or purchase as I am sent back to an instruction telling mee to go to the app store icon.
    How difficult can it be to simply purchase the software on-line have it shipped to you so you can install it, in the event it cannot be downloaded as it appears it can't be based on my curent operating systems being Mac OSX 10.5.8.

    Requirements for OS X 10.6 'Snow Leopard'
    http://support.apple.com/kb/SP575
    Whilst Apple have withdrawn Snow Leopard from download, you can still get it from Apple by calling 1-800-MY-APPLE (if you are in the USA) and they will supply the SL DVD for $30.  You can also purchase the code to use to download Lion from the same number.
    Requirements for Mountain Lion:
    http://www.apple.com/osx/specs/

  • Since I upgraded to the new iOS 7 operating system for my iphone, I can no longer adjust the volume on my alarm. No matter what setting the volume of my phone is my alarm is always full blast. Since I hate being startled awake, what can I do?

    Since I upgraded to the new iOS 7 operating system for my iphone, I can no longer adjust the volume on my alarm. No matter what setting the volume of my phone is my alarm is always full blast. Since I hate being startled awake, what can I do?

    Go to your home screen, and then press the volume down or up button. It should say Ringer instead of volume. If it doesn't do that, try going into the clock app and try it there.

  • During automatic creation of the purchase requisition to operation 0010

    Hi,
    Problem occurs in automatic cration of PR.
    Error : During automatic creation of the purchase requisition to operation 0010, an error (06 532) occurred:message c2325
    Regards,
    Vivek

    Hi ,
    I am getting error in CO01 Transaction.
    Message no. C2325
    For further proceedings, read the long text of error message (06 532) in transaction SE91. Check the operation affected and change or complete any missing data that led to the error message.
    Regards,
    Vivek Nehete

  • Why do I get the message that my operating system is not supported?

    My computer is running Windows 7 - 64-bit. I have the latest softwear on both my iPhone and my iPad. I have installed Edge Inspect on these devices and have the Google Chrome edge inspect extension installed. I have been able to enter my passcodes for both devices in the Chrome extension. Why do I get the message that my operating system is not supported just yet?

    This is VERY interesting ... even though I got that strange message, once I linked my iPhone and my iPad to the Google extension, it worked! Whatever I display in Google Chrome automatically displays in the Edge Inspect app on the small devices. This is neat! The only problem that I can see is that Adobe needs to replace the error message with information about how to use the application.

  • Are the read and write operations atomic for an array in a local variable.

    Hi,
    I would like to know when you access an array in a local variable, is it an atomic operation?
    Thanks,
    Mat

    Thanks for the comments. I agree with you. However, I my case, race conditions and synchronization are not issues. Therefore, the only thing that matters to me is that the write and read operation of the array must be atomic. I know that I can implement that with a LV2 style global but I want to avoid it if possible.
    If writing and reading to an array are atomic operations then I can simply use local or global variables.
    All I need to know is: Is reading or writing an array in a local variable an atomic operation?
    Thanks,
    Mat

  • Learning the basics of EXISTS operator

    I am learning the basics of EXISTS operator.
    create table loans
    (acc_id number,
    balance number(10,2));
    insert into loans
      (acc_id, balance)
    values
      (100, 20000);
    insert into loans
      (acc_id, balance)
    values
      (110, 22000);
    insert into loans
      (acc_id, balance)
    values
      (120, 7000);
    insert into loans
      (acc_id, balance)
    values
      (130, 172.99);
    SQL> select * from loans;
        ACC_ID    BALANCE
           100      20000
           110      22000
           120       7000
           130     172.99
    create table defaulters
      (cust_id number,
       name    varchar2(20),
       acc_id  number);
    insert into defaulters
      (cust_id, name, acc_id)
    values
      (1,'Vajaal',110);
    insert into defaulters
      (cust_id, name, acc_id)
    values
      (2,'Mostert',130);
    SQL> select * from defaulters;
       CUST_ID NAME                     ACC_ID
             1 Vajaal                      110
             2 Mostert                     130
    SQL> select acc_id from loans
      2  where exists(select 1 from defaulters
      3  where loans.acc_id=defaulters.acc_id);
        ACC_ID
           110
           130It just returns all acc_id rows in Loans table which has corresponding ACC_IDs present in defaulters.
    On 10gR2 SQL Reference, for EXISTS operator, it says ' An EXISTS condition tests for existence of rows in a subquery' .
    Would it be wrong if i say, EXISTS operator can be used when you want to return all rows in the Outerquery which has matching records in the Innerquery.

    Would it be wrong if i say, EXISTS operator
    can be used when you want to return all rows in the
    Outerquery which has matching records in the
    Innerquery.Depends on what you understand with "matching".
    See following examples:
    In this case matching means "<>" i.e. return all loans who have at least one row that differs in defaulters table (of course it returns all loans, because defaulters has 2 rows with different acc_id, BTW look also for NULLs and comparisons involving NULLs)
    SQL> ed
    Wrote file afiedt.buf
      1  select acc_id from loans
      2  where exists(
      3    select 1 from defaulters
      4*   where loans.acc_id<>defaulters.acc_id)
    SQL> /
        ACC_ID
           100
           110
           120
           130See also following query:
    SQL> ed
    Wrote file afiedt.buf
      1  select acc_id from loans
      2  where exists(
      3    select 1 from defaulters
      4* )
    SQL> /
        ACC_ID
           100
           110
           120
           130There isn't any condition at all, so any row in defaulters is "matching" row in this case.
    So I'd stick with explanation in documentation this time ;)
    Gints Plivna
    http://www.gplivna.eu

  • Prod order qty at the end of each operation

    Hi, my client want to monitor the qty of a production order at the end of each operation. can it be possible? say at the end of operation 10, the product A qty is 5, at the end of operation 20, the product B qty is 4 etc. pls advise what are all required to implement.

    Yadav,
    As suggested by the forum members you need to have operation confirmations i.e. CO11N.
    You can see the required report in COOIS or in the order itself against the every individual operations as confirmed quantity in operation overview.
    But as you required, it won't be inprocess material specific as you are not going to identify the inprocess stages as individual materials.
    Lets take as example, you have raw materials X,Y & SFG Z to have finished product A. The order contains 10 operations.
    We have issued X, Y & Z to the order on first operation. Now as per your client's requirement at the end of first operation that inprocess material will be identify with specific material code say P, at the end of second operation it would be Q & so on with quantity.
    But we don't define the inprocess material as particular material, you won't be having the same data.
    Even if you try it would be tedious job.
    So use standard report with the fields available. Or else go for customized report.
    Hope this helps you.
    SmanS

  • How to remove the Char.from one Operating Concern

    Hi Guys,
    How to remove the Char. from one Operating Concern.
    I have created one Char. (WWDOC) and moved to Operating Concern (OOCC). Operating Concern is in red status.
    Now, i want to remove that new assigned Char. (WWDOC)from the operating concern (OOCC). I did't find any option in the menu also.
    Appreciate your help.....
    T&R
    VVR

    Hi Sasi,
    Iam not able to push back that char. from my operating concern. In help it is given you have to delete the data contents in the table before pushing back. Please let me know if any other option available.
    Thanks for your reply.
    VVR

  • What is the differene between filter operation and NL semi join?

    Hi, all.
    The oracle is 10gR2 and 11gR2.
    There are differences between filter operation and HASH/MERGE semi join in processing subqueries.
    But I could not see the difference between filter operation and NL semi join?
    (the only thing I know is that filter operation has caching mechanism, but I am not sure in case of NL semi)
    What are the pros and cons of each of them?
    Thanks in advance.
    Best Regards.

    >
    The oracle is 10gR2 and 11gR2.
    >
    Those aren't 'version's. What are the 4 digit versions?
    >
    There are differences between filter operation and HASH/MERGE semi join in processing subqueries.
    >
    What are they? When you make a statement like that post the information (and links to it) that backs up your statement.
    >
    But I could not see the difference between filter operation and NL semi join?
    (the only thing I know is that filter operation has caching mechanism, but I am not sure in case of NL semi)
    >
    We can't 'see the difference' either; you didn't post anything for us to look at.
    >
    What are the pros and cons of each of them?
    >
    Each of what? Again - you need to be as specific as possible if you want specific feedback.
    Also, since you generally should not use hints in production code anyway what difference does it make what the differences are? Oracle will make the choice.
    Without anything specific to comment on about all we can do is provide several links that talk about joins and how to produce and examine them. These are all from Jonathan Lewis's Scratchpad:
    http://jonathanlewis.wordpress.com/?s=semi-join
    http://jonathanlewis.wordpress.com/2010/12/20/index-join-4/
    http://jonathanlewis.wordpress.com/2010/08/15/joins-mj/ -- merge joins
    http://jonathanlewis.wordpress.com/2010/08/10/joins-hj/ -- hash joins
    http://jonathanlewis.wordpress.com/2010/08/09/joins-nlj/ -- nested loop joings
    http://jonathanlewis.wordpress.com/2011/06/08/how-to-hint-1/ -- how to hint for joins
    Check out those articles. Pay attention to how, in each one, he doesn't just provide a text description but also provides code and explains the code.
    In other words he provides all of the specific information needed to illustrate what he is talking about. That is what you need to do if you need help with a specific topic: provide the query, plans and output that you yourself are using as the basis of your question. That lets us see EXACTLY what you are talking about.

  • Printing the Pick List at operation level

    Hi all,
    Is  it possible to Print the Pick List at operation level.
    Components are assigned  to each operations and release of  production order takes place at operational level. Once operation is released then only relavent component assigned to that particular operation should come in pick list.
    Thanks in advance for your time and efforts.
    Regards,
    Siva
    Edited by: Siva Kumar M on May 19, 2008 3:40 PM

    Hi ,
    System will not select the Opertaion which has status CRTD by default.
    For further selection please try with below settings. ,
    Profile = std profile
    Production Order Number,
    Selection at Operation level
    System status = CRTD  and Actiavte Excl .check box.
    Now system will display the pick list for  released operation and it`s component only 
    Please check, Reward if it is useful.
    Pradeep
    Edited by: Pradeep Kumar on May 19, 2008 3:45 PM

  • Can you Please Tell Me the Process for service/operation  provide by one plant to other plant.

    Can you Please Tell Me the Process for service/operation  provide by one plant to other plant.
    In My Company No Of Plants Like 1000,2000,3000,4000
    Plant 1000 Provide the service/operation  like (welding ,cutting, painting ) to other plants (eg 2000,3000,4000)
    We want to give the profit for plant 1000 and book the service or operation charge in plant 2000 or 3000.
    We don’t want  to use material code in this process.
    Can you help me it is possible or not through SAP PP.

    Krishnendu,
                   Actually in my company we have one plant 1000 that plant provide the service like (CUTTING (SHAFT),WELDING,MACHINING,PAINTING)
    actually plant already made one material xyz and supply 2000 plant .
    we  can use STO in this scenario and set special procurement key  80.
    But my requirement is after some time plant 1000 provide few operation in xyz material that material already supply to 2000 plant.
    in this case we dont  use to produce any material.

Maybe you are looking for

  • COPA datasource error - Errors occurred during the extraction

    Hi, I have an issue with the COPA datasource, 1. I have created a COPA datasource in DEV and its working fine in DEV. the entire extraction is working fine. 2. Then I transported this copa datasource to QA where I am getting belor error. In Extract c

  • ORA-01401 with export/import

    Hi! I'm trying to migrate database from from version 8.0 on novell to 9.2 on Linux. I have precreated all tablespaces and all tables are succesfully created. In data import stage I got lot of "ORA-01401 inserted value too large for column" errors. An

  • Ho to install the "BC4J Enterprise Manager Bean" in Application Server 10g

    Hi I'd like to monitor my BC4J Application installed on a 10g Application Server. According to the help system I can find this information on the Enterprise Manager Website of the 10g Application Server: open the OC4J (not "home" in my case), open "A

  • Pls advise PSU and CPU temp.

    At last i have decided to go for Herolchi HEC 525w Dual Fan Ball Bearing ATX Power Supply, after installing the New PSU my CPU Temperature go up by 3 degree...not sure whether all the RAIL will effect the temperature ? Pls take a look on my compariso

  • HELP!  Can't apply iTunes 7.0.2 Update

    I have never had a problem updating iTunes before, but this release it has not let me update. I go to to download the update and it says I have downloaded, but I know I haven't applied it. And every couple of days when I start up iTunes I get the sam