简体   繁体   中英

How can I save generic Type information in xcore model?

I would like to have a model that contains a name and object type. The type could be any object type, not necessarily restricted to other models, so I don't want to use EDataType for this. How can I do this?

Basically something like this:

class GenericParameter
{
    /*
     * The data type of the parameter
     */
    Type datatype

    /*
     * Parameter name
     */     
    String name
}

I can't seem to import this from java.lang.reflect. The resulting error is: "Type cannot be resolved to a type." The intent is to store meta information about permissible parameters in a larger system. I could just use a straight up generic Object but I feel like that's cheating, especially since I don't care about any specific object itself anyway, just the type.

Classy hacking question you ask

public <E extends Object> void set(E ref);

public <E extends Object> E get();

If you're trying to derive the code somehow, your best bet is to get the name of the class, and use reflection to load the class name instances, if the reference is not found, you don't have the library you're attempting to reference in the JVM you are attempting to do so in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM