How can we access type and subtypes of enum in java? -
i need implement following using enum
.
import java.util.*; /** * * @author mukesh */ public class mytest { private list<subtypes> subtypes = new arraylist<subtypes>(); enum types { percentarea, stackedarea, chartsubtype3; } enum subtypes { persentarea1(types.percentarea), persentarea2(types.percentarea), persentarea3(types.percentarea), stackarea1(types.stackedarea), stackarea2(types.stackedarea), stackarea3(types.stackedarea); types t; private subtypes(types t) { this.t = t; } } public list<subtypes> getsubtypes() { return collections.unmodifiablelist(subtypes); } public static void main(string[] args) { /* how can subtypes based on base type ??? */ }}
example :
suppose in 1 combo have types
- percentarea
, stackedarea
, chartsubtype3
etc. , if select percentarea
second combo can sub types e.g. persentarea1
, persentarea2
etc.
can 1 guide me how can retrieve values of subtype given types.
i think need this
private static void getsubtypes(types type) { subtypes[] values = subtypes.values(); for(subtypes value : values) { if(value.t == type){ system.out.println("found subtype "+ value); } } }
hope helps!
good luck!
Comments
Post a Comment