Check allocation object casting

Hi
Is there some function to check an object data for possible cast.
Ive this sheet code for exemple
Object obj1;
Object obj2;
Object obj3;
JTree tree;
JMenu menu;
// Normaly it's not possible to cast fromm menu to tree
obj1 = (Object)tree;
obj2 = (Object)menu;
Now i would like to check the real instance of the object
ex :
if obj1 is an instance of JTree
do something
else obj1 is an instance of JMenu
do something else.
The only solution to do this i've founded is use java.lang.ClassCastException
Thanx for help

Jeez, you were that close:
if(obj instanceof JTree)
    // something
else if(obj instanceof JMenu)
    // something else
}Enjoy,
Radish21

Similar Messages

  • GATP allocation object

    Hi all
    In the step "Check the Product Allocation Settings" I get following error message
    "Product allocation object xxxxxxxxx is not contained in the hierarchy or in the characteristics combinations of product allocation group yyyyyy"
    The characteristic combinations are generated for the PLOB. The value of the DP characteristic  corresponding to KONOB  as well as the Product allocation object in customizing is not numeric but alpha and 9 characters. I have thoroughly  checked this value to be to be identical.
    I suspect the mismatch is occuring because of the way the value is stored in planning area and ATP tables. The characteristic length itself is 18. Any experience or insights on this issue?
    Thanks in advance

    I take back the statement of though check, found the error, closing the issue.

  • Problem to check out object in siebel 8.1, using Windows Vista

    Hi people,
    i'm quite new to siebel and recently, i am supposed to start developing applets and BCs. The problem is, i cant check out object from the server. whenever i hit the button Check Out, the system (Siebel 8.1) is hang and stop responding. Can anyone help me on this? Thank you so much.
    Zaly#

    Hi,
    i've tried both ODBC, SSD Default instance and SSD Local Db default instance. Both yielded same result, which the connection is successful. But for SSD Default Instance, whenever i tried to hit the button 'Test Connect' for 2nd time or more, it will stop responding and hang. Only the first time is succesful.
    I really dont have the idea how the problem occurs. but it works well if i do check out in computer that runs on window XP. Is the problem comes because i'm using vista?

  • Can we check the Objects modifiable " option for standard objects

    Dear Friends
                 In IR , we have imported SRM SERVER->SRM SERVER5.5
    Then we  have checked the option<u><b> "Objects are modifiable"</b></u> then we imported the IDOC from R/3 system under SRM SERVER 5.5 swcv.
    Then created the mapping.It is working fime.
    how ever i am not sure whether it is right process.Can we check the "Objects are modifiable" for standard compoents delivered by SAP????
    Regards
    chandra

    Hi Jai,
      <i> >>>Can we check the "Objects are modifiable" for standard compoents delivered by SAP????
    No. As best practise you are not supposed to do so.</i>
    In order to implement any changes in the mapping we can do it rite.
    Because recently i have applied one SAP note to my SRM swcv and one of the MM object was changed according to the requirements.
    Thanks,
    Prasanthi.

  • Object Casting

    hi ,i have a question for .Base on this example below , i need to understand some casting basic .I understand how premitives values widening rules works but not on object casting rules.
    Question 1.
    Okay ,base on the example below why 'c=(Test) a' will always give compile error while "a=b" does not .Let takes this example , b already extends A and should have information of A class while A only have it own .I know i was thinking another way round.Can any one help.
    Question 2.
    How to make " c = (Test) a to run without any problem ,as long as a is assign to a is ok.
    Question 3.
    I have a statement from Khalid book page 202 and i don't understand .
    First statement:=Conversion which preserve the inheritance is a relationship are allowed ,other conversion      require an explicit case or are illegal.
    Fecond statement:=There is no notion of promotion for reference values.
    Question 4.
    What is the benefit of using casting and when we need to use it .Can give a short example.??
    class A {int Athing = 1;}
    class B extends A {int Bthing = 2;}
    class Test extends A
    { int Cthing = 3;
    public static void main(String args[])
    A a = new A();
    B b = new B();
    Test c = new Test();
    //c = (Test) a; //runtime error
    a = b;

    Ron, does your mommy know you're here? Shoudn't you be out riding your bike or doing homework or watching X Men or something instead of interrupting the grown-ups?
    Wikey: The answer to your question is that you can always (and implicitly) cast to a subclass because the subclass is always a member of the class, but you can't always even explicitly cast to the parent or higher class. To give a concrete example, all Toyota Camries are cars, but not all cars are Toyota Camries. There are things you can do with a Toyota Camry that you can't do with all cars. In your code, if you had coded A a = new Test();, you woudn't have a runtime error.
    Doug

  • BAPI for Allocating Object to Class

    Hi all Experts,
    Pls help in how to use the following BAPIs.
    BAPI_OBJCL_CREATE_KEY
    BAPI_OBJCL_CHANGE_KEY
    OR else provide me any other BAPI avaliable for Allocating Object to Class in MASS Processing / Single Entries.
    Regards
    Nagarajan M

    Hello,
    have a look at the following thread. There're some function modules that should fit to your requirements:
    BAPI for CL24N
    Best regards
    Stephan

  • Need precision on dynamically allocated objects

    Hi all,
    For example, I declare this class :
    package Global
    public class GV
    public static var gLogin:String="123";
    public static var gPassword:String="4567";
    public function test(t:int):int {
    return t+1;
    Flex lets me use my class this way to access a static member
    import Global.*;
    GV.gLogin='XXX';
    In this case, a GV object is dynamically allocated and the
    static member is set.
    Now I want to call the test method using the same dyn alloc :
    import Global.*;
    GV.test(123);
    Flex gives me a "Unknown method" error.
    So this is my question : Why can I access a static member but
    not a method on a dyn alloc object ? Is there a way to do this ?
    Thank you for your help :-)
    MiF

    Shame on me !
    I did not know that a function could be static.
    Thank you for your help Simon.

  • Hi i just to want to know when we use object casting..

    sorry about this newbie question i ve already asked to my tutor but
    didn't get it...
    i just wonder what will happen if we cast object..
    i just can't imagin..coz im just bit slow on creative thinking...
    my currently writing code is like this..
    Integer nextCustID = new Integer("123456");
    Customer customer = new Customer(nextCustID, "Fred");
    customers.put("First", customer);
    customer = (Customer) customers.get("First");
    System.out.println(customer);i don't know about object casting...............................

    You don't cast objects. You just cast references - widening or narrowing their "scope" along the inheritance hierarchy.
    String s = new String("Hello");
    Object o = (Object) s; // Explicit cast not necessary, just for clarification
    String s = (String) o;While "hello" might appear as a String, then as an Object, then again as a String, it is always a String. Only the reference type to it changes.

  • Check maintainance object or function group in sm30

    hi,
    my abaper create a table maintainnce view and function group . it working fine in developement system but when i transport it to quality system and then open table view in sm30 it s showing error check maintainance object or function group.
    please provide me the soloution.

    Hi,
    Was the import successful into the QA system? Check the import logs and RC to see if there were any errors/warning reported.
    Also, run the syntax check for the functional module in QA to get more information about the error.
    You might have to involve the ABAP consultant to get this resolved.
    Regards,
    Varun

  • Finding existing allocated object ID numbers in OID & OVD

    Is there any way to find the object IDs that are already used in OID and OVD?
    I need to create some new attributes - so I'll need to assign new object IDs to these attributes - and I want these to continue on from IDs that have previously been assigned (and obviously, be different numbers).
    I can see that I can use the Oracle Directory Services Manager to find the Object ID for each individual attribute we already have set up by clicking on each individual attribute in the Schema tab, but given that we have a couple of thousand attributes, that's not very practical.
    Is there some other way to view to allocated Object IDs via the DSM, or some query I can run on the OID & OVD databases?
    Thanks

    Actually, the fact that it's a string works for me here,
    since my custom formatter expects a string.
    That's the one last thing I'm confused about. Following the
    example I got from a book, I made my formatter. And it was the
    place I got the "myNumber" thing. So how would I modify my
    FractionFormatter.as to eliminated the need to pass the string from
    the main file (if I understand correctly):
    package myComponents
    //Import base Formatter class
    import mx.formatters.Formatter
    public class FractionFormatter extends Formatter {
    // Declare the variable to hold the pattern string.
    public var myNumber:String;
    // Constructor
    public function FractionFormatter() {
    // Call base class constructor.
    super();
    // Override format().
    override public function format(value:Object):String {
    //Validate value - it must be a nonzero length string.
    if(value.length == 0) {
    // Return empty string and error message for zero-length
    string.
    error="Zero Length String";
    return ""
    //If the value is valid, format the string.
    switch (myNumber) {
    case ".25" :
    return "1/4";
    break;
    case ".5":
    return "1/2";
    break;
    case ".75":
    return "3/4";
    break;
    case "1":
    return "1";
    break;
    case "1.25":
    return "1 1/4";
    break;
    default :
    // If formatString is not "upper" or "lower",
    // return empty string and set the error message.
    error="Invalid Format String";
    return "";
    }

  • Regarding checking the objects versions after transporting

    Hi
    we are doing transportation from DEV to  QAS. what we have done is
    we have collected all master data objects,data sorses,transformations,dtps,process chains into different transport recquests and releases the recquests ,and imported recq in QAS.
    now our recq is to check whether all master data objects,data sorses,transformations,dtps,process chains are transported or not
    if transported have to check all obj are in active version or not.
    at present we are follwing below procedure
    a) go to se09 in DEV and select 1 recq and check the objects list under that recq then copy one obj and check in QAS,the same procedure for all objects, but we are having 100 recquests, under each recq we are having many objects.
    if we follow that it wil take days,so is there any procedure to check
    are there any tables where we can check fast and minimise the time.

    am not sure about the object status however can get list of objects in your transports from below process :
    Go to table E071 and give your request numbers as input. It will give you list of all the objects contained in those requests.
    Now object will be of different types , IOBJ - Infoobjects , ODSO - ODS , MPRO - Multiprovider , TRFN - Transformation etc.

  • How can I check an object is an instance of any type within an array of related types?

    In LabVIEW, it's possible to check the runtime type of an object using To More Specific Class.vi. One usage of this would be to perform a safety check if some kind of class uses instances of another kind of class but is only able to handle a subset of that class' child types.
    For instance, let's say you had Beverage.lvclass, which represents an abstract type of product, and several subclasses: Coffee.lvclass, Tea.lvclass and Soda.lvclass.
    We also have a Person.lvclass which can drink beverages. A person also has preferences about the drinks they do or do not like:
    Attached is an implementation of this in LabVIEW.
    In Person.lvclass : Drink.vi, I have the following code. For whatever reason the wire appears broken in these snippets but it's all fine in the actual code.
    In Scenario.vi, I have the following code:
    What I'm finding is that no error is generated and instead I get "Yum, I love tea!", "Yum, I love coffee!" and "Yum, I love soda!". My guess is that To More Specific Class.vi casts to the static type of the "target class" input wire rather than its runtime type - and because I'm passing in elements from an array of types, the wire's static type is upcasted to the most specific type that is a superclass of the types in the array - which would be Beverage.lvclass. And so the cast is trying to determine if an object of static type Beverage.lvclass is an instance of Beverage.lvclass, which will of course be the case all the time.
    Is there any way to make LabVIEW check against the most specific runtype type of an object? As in, is there something I could do that, in this example case, would allow me to get the required behaviour of Joe throwing an error when he's made to drink soda? Or is this another limitation of LabVIEW that I'm going to have to live with?
    Solved!
    Go to Solution.
    Attachments:
    TypeCastingExample.zip ‏64 KB

    tst wrote:
    Your guess seems reasonable. I can't check right now, but there's a primitive called preserve run time type, which should do what you want.
    Cheers, that seems to have got it! I've never really looked at Preserve Run-Time Class before, but it seems to do the right thing.

  • Object casting: confusion in ABAP Objects: Complete Reference book

    Hi,
    During Object Assignments using casting, is a Type Test carried out during the syntax check or at runtime?
    A.5.2.2 (page 1008) of 'ABAP Objects: The Complete Reference' says about Widening Cast: "...you must check at runtime...". However on the next page under A.5.3.2 it says of Widening Cast in Data References: "The syntax check precludes...".
    A.5.4 (page 1010) concerns Assignments between Object Reference Variables, but makes no mention of whether checks are carried out by a syntax check or at runtime.
    Also nowhere does it mention when Type Tests for Narrow casting takes place. Can anyone clear my confusion please? Unfortunatly I don't know enough about this stuff to test by writing some code.
    Thanks.

    William,
    Your questions can be answered by the following rule for object references, which I found in the book "ABAP Objects" by Horst Keller and Sascha Krüger:
    "... that the static type of the target variable must be equal to or more general than the dynamic type of the source variable."
    Here "static type" means the type with which an object reference variable is declared. "Dynamic type" is the type that the object reference variable has at runtime. The dynamic type of an object reference is always more special than its static type, otherwise a runtime error occurs.
    With this rule all your questions can be answered:
    1. The Narrowing Cast is always checked during the syntax check. Example:
    DATA o_ref1 TYPE REF TO object.
    DATA o_ref2 TYPE REF TO class_1.
    o_ref1 = o_ref2.  
    Here the reference o_ref2 has a dynamic type "class_1" or a subclass of it, which is narrower than its static type "class_1", which is narrower than the static type "object" of the reference o_ref1. Therefore, the syntax check says that the assignment is OK.
    2. The Widening Cast is always checked at runtime and requires an assignment using the operator ?=. If you use the operator = in the assignment, a syntax error occurs. Therefore the following  example produces a syntax error (try it yourself):
    DATA o_ref1 TYPE REF TO object.
    DATA o_ref2 TYPE REF TO class_1.
    o_ref2 = o_ref1.  
    The correction for this syntax error is:
    DATA o_ref1 TYPE REF TO object.
    DATA o_ref2 TYPE REF TO class_1.
    o_ref2 ?= o_ref1.
    Now the syntax check is satified, and the correctness of the widening cast is checked at runtime.
    Kind regards,
    Michael Kraemer
    Message was edited by: Michael Kraemer

  • When should object casting be used?

    Hi,
    just wondering something. Saw there that returning objects from methods and downcasting the returned object is bad. When should casting be used? I currently have a program that has an object that contains a HashMap as a field. When I try retrieve objects from the HashMap using the relevant key, I have to cast them to what they were originally! Is this bad programming practice or is it the only way to do things?
    Thanks.
    // example of retrieving object from key
    dbDirectory = (String)dbInfo.get("dbDirectory");

    LeWalrus wrote:
    Hi,
    just wondering something. Saw there that returning objects from methods and downcasting the returned object is bad. When should casting be used? I currently have a program that has an object that contains a HashMap as a field. When I try retrieve objects from the HashMap using the relevant key, I have to cast them to what they were originally! Is this bad programming practice or is it the only way to do things?
    Thanks.
    // example of retrieving object from key
    dbDirectory = (String)dbInfo.get("dbDirectory");
    Before generics, this was a perfectly acceptable practice. Generally speaking, you use type-casting when the compiler is unable to ensure the type validity at compile-time, but you know it is correct, so you supply the extra information to the compiler so it knows everything is correct. Sometimes you need to circumvent the strong type-checking part of the language for flexibility, but this is something that should be used very sparingly.
    Now it would be better to use generics so that the compiler will know at compile time that the values in your map are Strings, instead of just Objects.

  • Object Casting confusion

    Hello,
    I have two classes used in the insurance business. One is a Member, which is someone covered by insurance (eg. an Employee, Spouse, Dependent) and one is a Employee which is more specificly the person who actually has the insurance.
    I am reading records of a database and creating each record into a Member Object. My Employee object extends Member. I want to know put the business logic in my main method to determine which Members is an Employee, Dependent, or Spouse.
    I am explicitly casting down the hierarchy, which I thought was allowable. I even implemented Cloneable on the Member object to try to get it work. The compiler seems to be fine with it, but I keep getting a runtime error: "ClassCastException".
    I am trying to avoid extracting the information from Member and having to reassemble it into Employee by using inheritance. What am I missing?
    Thanks.
    public class Member implements Cloneable
         private Object ssn;
         private Object planNumber;
         private Object locationCode;
         private Object coverageType;
         private Object benefit;
         private Object hireDate;
         private Object retireDate;
         private Object lastName;
         private Object firstName;
         private Object middleInitial;
         private Object address;
         private Object city;
         private Object state;
         private Object zip;
         private Object dob;
         private Object doh;
         private Object relationship;
         private Object gender;
         private Object effectiveDate;
         private Object status;
         private Object order; //represents order in spreadsheet
         //setters
         public void setOrder(Object order) {this.order = order;}
         public void setSSN(Object ssn){this.ssn = ssn;}
         public void setPlanNumber(Object planNumber){this.planNumber =planNumber;}
         public void setLocationCode(Object locationCode){this.locationCode = locationCode;}
         public void setCoverageType(Object coverageType){this.coverageType=coverageType;}
         public void setBenefit(Object benefit){this.benefit=benefit;}
         public void setHireDate(Object hireDate){this.hireDate=hireDate;}
         public void setRetireDate(Object retireDate){this.retireDate = retireDate;}
         public void setLastName(Object lastName){this.lastName= lastName;}
         public void setFirstName(Object firstName){this.firstName=firstName;}
         public void setMiddleInitial (Object middleInitial){this.middleInitial=middleInitial;}
         public void setAddress(Object address){this.address = address;}
         public void setCity(Object city){this.city = city;}
         public void setState(Object state){this.state = state;}
         public void setZip(Object zip){this.zip=zip;}
         public void setDOB(Object dob){this.dob=dob;}
         public void setDOH(Object doh){this.doh=doh;}
         public void setGender(Object gender){this.gender=gender;}
         public void setEffectiveDate(Object effectiveDate){this.effectiveDate=effectiveDate;}
         public void setStatus(Object status){this.status=status;}
         public void setRelationship(Object relationship){this.relationship = relationship;}
         //getters
         public Object getSSN(){return this.ssn;}
         public Object getPlanNumber(){return this.planNumber;}
         public Object getLocationCode(){return this.locationCode;}
         public Object getCoverageType(){return this.coverageType;}
         public Object getBenefit(){return this.benefit;}
         public Object getHireDate(){return this.hireDate;}
         public Object getRetireDate(){return this.retireDate;}
         public Object getLastName(){return this.lastName;}
         public Object getFirstName(){return this.firstName;}
         public Object getMiddleInitial(){return this.middleInitial;}
         public Object getAddress(){return this.address;}
         public Object getCity(){return this.city;}
         public Object getState(){return this.state;}
         public Object getZip(){return this.zip;}
         public Object getDOB(){return this.dob;}
         public Object getDOH(){return this.doh;}
         public Object getGender(){return this.gender;}
         public Object getEffectiveDate(){return this.effectiveDate;}
         public Object getStatus(){return this.status;}
         public Object getOrder() {return order;}
         public Object getRelationship(){return relationship;}
    }//end class
    import java.util.*;
    public class Employee extends Member
         Employee()
         private Spouse spouse;
         private Dependent dependent;
         private ArrayList dependents;
         private static int numberOfDependents;
         public void setSpouse(Spouse spouse){this.spouse = spouse;}
         public Spouse getSpouse(){return this.spouse;}
         public Dependent getDependent(int n)
              dependent = (Dependent)dependents.get(n);
              return dependent;
         public void setDependent(Dependent dependent)
              ++numberOfDependents;
              this.dependent = dependent;
              this.dependents.add(dependent);
         public ArrayList getDependents()
              return dependents;
         public void setDependents(ArrayList dependents)
              this.dependents = dependents;
         public int getNumberOfDependents()
              return numberOfDependents;
    }//end class
    import java.util.*;
    //Employee objects can be selfstanding Employee(String SSN)
    //The Spouse and Dependent objects - e.g. Spouse(String SSN, e)
    public class InsuranceObjectDriver
    //     ****************** START MAIN **********************************     
         public static void main(String[] args)
              //Open connection and query table
              DatabaseObjects db = new DatabaseObjects("LIBRARY", "", "");     
              db.queryDb("Table1");
              ArrayList memberList = db.getAllRecords();
              Member member;
                   member = (Member)memberList.get(0);
                   if (member.getRelationship().equals("E"))
                        Employee e =(Employee) member;
                   }

    >
    I see nothing wrong with the casting, since Employee
    is a Member.
    My only assumption is that the actual instance of
    "member" is not an Employee...so check your
    getRelationship().equals("E") condition...it may give
    you true, where it should have been false.This is why I'm casting it explicity to a Employee
    For design-wise, I see Employee, Spouse, and
    Dependent are more of a Member role..and not a
    "Member" superclass. I don't understand what you are trying to tell me here. Member is the superclass. Employee, Spouse, and Dependent are subclasses of the Member, which is one of the problems. I have to explicity cast down the hierarchy.
    Plus, what's with all the
    "Object" in the Member class? I never seen anyone
    did this before.
    I understand that by defining the Member attributes
    as Object, you can
    set the underlying type to anything in the
    future...without having to change the code...but i
    think this is a bad idea (just my thought).I like it. It dummy proofs things a bit. The input files are often sloppy and bad, plus I really don't care to maipulate most of these fields, I just need to make sure they populate the objects.
    E.g. I build a quick and dirty application for non-techies, who don't pay attention to data types much (in my many experiences). I don't want the program to bomb out on Date of Hire (doh) because it was brought in through the JDBC connection as an Object and not a Date.
    Data is brought into the application from the resultset via a getObject(n) call. Why change it? I guess I could use wrapper classes for them but I can't see why right now, but will consider this when I figure out the casting issue.

Maybe you are looking for

  • Since updating to Lion the iMac won't recognise the external hard drive (maxtor) when waking from sleep mode,

    Hi All, Since updating to Lion, my imac won't recognise the ext HDD (Maxtor) when waking from sleep mode, I have tried another port, diisc utility (Ext HDD not listed in here) but nothing works. I now find that I have to restart the imac to get the d

  • HT1222 Error occurred installing iOs 7.0 & 7.0.2

    Hi, I unable update my iphone 5 software to iOs 7.0 (when verify updating, an error occurred installing iOs 7.0.2). Please do advise for the software update. Wish to get your reply. Thanks!

  • Unable to read Windows 7network in Bridge CS5

    When I try to read folders on my network BR CS5 freezes.  I can move files from the network using Windows Explorer, but BR CS5 freezes.  The drives are not mapped to my laptop. Any suggestions? Thanks,

  • Migrating Cognos Reports to Birt

    Hi, I am relatively less familiar with Cognos. What is the best way to migrate a bunch of Cognos Reports to Birt. I have the Cognos Report files and the query definition file from Cognos. Any help will be greatly appreciated.

  • Filtering documents to create

    Dear Firendas, Weu2019ve created two different role configuration keys for our project, so we have two different configurations for many components. Weu2019ve create many types of documents (IMG, CRM, Transactions, Basic Settings, Define Transaction