DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2005
    Posts
    5

    dynamic object identification problem

    ok, I have a class that takes 3 inputs.
    Variable(NAME, TYPE, DATA);
    the name is a string, the type is a string, however the DATA is where it gets tricky.

    DATA depends on what the string TYPE is. Example
    if TYPE is a String
    DATA isa String
    if TYPE is a VectorObject
    DATA isa VectorObject

    you get the idea right?
    Now, here's the problem. I don't know what to identify DATA as. It's type is determined at runtime, not compiletime, so I don't know what to define it as, since a string cannot be coverted into VectorObject, plus i can't keep redefining DATA.


    Example:
    if TYPE isa VectorObject
    DATA isa VectorObject
    would be shown as VectorObject DATA = new VectorObject();
    the problem arises when i try to store or return the DATA object!

    public <omg i dont know what identifier goes here, b/c i don't know the type yet> GetData { return DATA;}
    So any ideas?
    There's got to be a better way to do this or something small that im missing.
    I'm not sure if i could use an interface for this situation, any suggestions?
    This is for a Java game scripting system im developing.

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468

    Arrow

    Read up on Java's implementation of Generics. It fits the bill you want to implement.

    Variable(String name, T type, T data)
    {...}


    public <T> T getData()
    {
    return DATA;
    }

    Here's a link to the "official" Generics tutorial, in pdf format:

    http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf

Similar Threads

  1. Replies: 5
    Last Post: 09-27-2002, 04:40 PM
  2. Replies: 0
    Last Post: 08-08-2002, 05:56 AM
  3. Javascript object function problem
    By sean in forum Web
    Replies: 1
    Last Post: 08-04-2002, 10:40 AM
  4. Replies: 6
    Last Post: 03-26-2002, 09:58 AM
  5. Object Modeling for the WEB
    By Greg Dirst in forum authorevents.appleman
    Replies: 1
    Last Post: 04-10-2000, 02:56 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links