Results 1 to 3 of 3

Thread: Cast superclass to subclass?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    95

    Cast superclass to subclass?

    Is there a method to convert a superclass to one of its subclasses?

    More specifically: I have a function that returns an Object class There's no way around this -- it has to return an Object. It's actually a generic "List" class used to store any type of data in a list. I don't want to wander too far off course here. Bottom line: It was to be an Object.

    I do, however, know that it will only return a CDataSet class, because I'm only using it to store CDataSet objects. How can I 'convert' the returned Object class to a CDataSet object?

    (Note: CDataSet is a custom class).

    Thanks

  2. #2

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Code:
     public class Q{
      public static void main(String[] args){
     
       Q q = new Q(); 
       String s = (String)q.getObject(); 
       System.out.println(s);       
    
     }
      private Object getObject(){
        return new String("String Object");  
     }
    }

Posting Permissions

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



Click Here to Expand Forum to Full Width