Hello, I just started getting into
Java a couple of weeks ago and i stumbled on a rather strange problem. Its about creating a Homogeneous or Heterogeneous collections in Java. So far I have created a generic BinaryTree class which can use every type i throw at it. So far just the basic one.
But i was wondering how would one implement a Collection which can take ANY type inside (such as
String,Double,Integer) all at the same time inside the same collection. As far as i know the collection should be of type Object. The problem i am facing is how would i implement that witohut having to repeat my BinaryTree class and just replacing the generic with object. Is it possible to make it all in one Collection that can take The same and different types of objects at the same time.
For the objects , being diffrent types and all i guess i should override compareTo and i plan on comparing different objects based on their hash code. Comparing is irrelevant in this case since the main idea is to force the collection to take same and different types at the same time.
I want to take ArrayList as an example, it can do exactly that.