Tuesday, 15 January 2013

java - Chaining Enumerations for hierarchical naming structures? -



java - Chaining Enumerations for hierarchical naming structures? -

since have terrible memory, set detnd ails of info objects enumerations, can utilize code completion in ide adon't have maintain referring name of table or name of field. utilize type of class containing enums purpose.

lets have table of "domains" (database source) "tables" , "fields" this:

public class dataobjectnames { public enum domains { domain1, domain2; } public enum domain1tables { customers, orders; } public enum domain2tables { orderitems, shipments; } public enum customerfields { id, email; } public enum orderfields { id, customerid; } //fields orderitems , shipments . . . }

but suppose wanted able like:

domain1.tables().customers.fields(). //code completion supplies choices?

what ot happen after type period autocomplete provide selection between .id , .email, much same if "fields" returned object 2 methods, or if typed customerfields. in ide.

in order happen, seems me somehow need homecoming not specific instance of enumeration, enumeration itself. i've tried various approaches this:

public enum domains { domain1 { @override public enum<?> tables() { homecoming domain1tables.foo(); } //is there method homecoming enum itself? }, domain2 { @override public enum<?> tables() { homecoming domain2tables.foo(); }; public abstract enum<?> tables(); }

but of course of study haven't been able find funciton foo() returns enum class itself.

any thoughts?

you can't enums because java's class model doesn't work way need in order style work.

i haven't been able find function foo() returns enum class itself.

returning enum class easy, domain1tables.class, won't give completion want because gives class<domain1tables> object, , object doesn't have fields named customers , orders.

you want able treat "domain1tables" class if it's object , refer enum constants (which static final fields) if members of object, java doesn't that.

if give on using enums it, can have:

public class dataobjectnames { public class domains { class domain1 { class tables { class customers { public static final string id = "id"; public static final string email = "email"; } } } } }

but in case dataobjectnames.domains.domain1 wouldn't valid look anymore (because reference class scope, not object.

there's solution you're trying do, without more context can provide more details what's above.

java reflection enums

No comments:

Post a Comment