×

Discussion Board

Results 1 to 2 of 2

Thread: Type casting

  1. #1
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,429

    Type casting

    Hi,
    I have a vector containing items(TextField, StringItem,etc) that are to be placed in a form using append()
    Is there any way to type cast the vector elements depending to the class type it belongs.

    regards
    Gopal

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    Sure, you can type cast them like any other object. And you can use the instanceof operator to find out what type they are at runtime:
    Code:
    Vector v;
    
    Object o = v.elementAt(1);
    if (o instanceof TextField) {
      TextField tf = (TextField)o;
      // ...
    }
    else if (o instanceof ImageItem) {
      ImageItem ii = (ImageItem)o;
      // ....
    }
    // etc.,etc.
    shmoove

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×