arrays - How to achive dynamic binding with ArrayList<T> in Java? -
it looks arraylist in java not support dynamic binding. when tried following code gave compile time error.
code:
class value { <some variables> <some methods> } class integervalue extends value { int value; } class charactervalue extends value { char value; } class main{ arraylist<value> values = null; public static void main(string args[]) { swtich(args[1]) { case "integer": values = new arraylist<integervalue>(); break; case "character": values = new arraylist<charactervalue>(); break; default: values = new arraylist<value>(); } } }
looks arraylist not support dynamic binding array does. when did value[] values = new integervalue[maxsize], did compiled creating references of superclass type. if dont know size @ beginning , want dynamic behaviour data structure (something arraylist can do) ? there other way achieve ? there other data structures ?
in advance.