A single data structure to store different types in a single variable.
Not asking for generics, some a dynamically typed data structure.
Is it possible?
A single data structure to store different types in a single variable.
Not asking for generics, some a dynamically typed data structure.
Is it possible?
You could just use Object as the variable type.
Not sure exactly what you are after. I'd argue that, in Java, it's Generics that provide dynamic typing.
Yes. All the data structures in the standard library end up using generics with type-erasure. Something like:
ArrayList<Object> dynamicData = new ArrayList<Object>();
should do just fine. Just remember, you will have to cast after you pull objects out of the structure.
I'm not 100% sure what you are asking, but all Java collections support un-typed data. For example:
List dataStructure = new LinkedList();
dataStructure.add(new Long(5));
dataStructure.add("Hello");
dataStructure.add(new BankAccount());
Technically since everything inherits from Object, coupled with autoboxing for primitives yes you can. Although without casts and heavy use of "if X instanceof Y" statements, you'll have a sticky time.