-
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.
-
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
-
By chida in forum ASP.NET
Replies: 5
Last Post: 09-27-2002, 04:40 PM
-
By scottish mike in forum .NET
Replies: 0
Last Post: 08-08-2002, 05:56 AM
-
Replies: 1
Last Post: 08-04-2002, 10:40 AM
-
By Marco Alves in forum .NET
Replies: 6
Last Post: 03-26-2002, 09:58 AM
-
By Greg Dirst in forum authorevents.appleman
Replies: 1
Last Post: 04-10-2000, 02:56 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks