Amandeep Singh wrote:My real question is, would it be fine to represent either String or Number as 1 common type as Object as shown in my changed code.
You will be better off referring to the Sets using their proper types. In the method that needs the Iterator, pass them in as Set<? extends Object>:
So you can maintain type safety elsewhere.
this is informative.
Note that I removed "extends Object". This is because "?" and "? extends Object" are basically the same since Object is the root of all class hierarchies. Similarly, if you ever see "? super Object" you can replace it with "Object".
you mean i should use objects only or ? .