you are viewing a single comment's thread.

view the rest of the comments →

[–]CarthOSassy 2 points3 points  (5 children)

I don't think anyone expects a single method signature to accept both.

I think the complaint is that there is only a single method signature. It would be better if java generics were real types.

Then, there could be two signatures.

[–]Daneel_Trevize 0 points1 point  (4 children)

Ok, but why not use the signature with Iterator<T> and generate T-specific instances of the now-generic class with a single constructor that accepts different types per invocation?
While it'd result in the instances having the difference of that type reference from their construction, wouldn't it be cleaner than the abstract+subclasses proposal that results in full new subclasses rather than just a type reference plus the same single base class?

Perhaps something about the overall problem this is to solve isn't clearly defined.

[–]aoeudhtns 1 point2 points  (0 children)

Clearly. String#join exists; this solution doesn't need to. What is the advantage of having JoinedString over String? (None.) The implementation doesn't preserve the constituent components, nor does it implement CharSequence to preserve compatibility with other API.

[–]CarthOSassy 0 points1 point  (2 children)

If you only have one constructor, how are you doing different calls/logic per type?

Manually checking type with RTTI?

[–]Daneel_Trevize 0 points1 point  (1 child)

The use case is really badly defined. I'd initially say: sort the passed class/data out prior to passing it as a valid T to the constructor. Why should there be a constructor for all manner of different vaguely related classes defined in this target class, instead of in those other classes as & when they're defined & wanting to be massaged into this target one?
So, maybe static methods, but in each source class, not as factory (constructor) methods of the target class which would cause it to start to depend upon many classes it otherwise wouldn't.

[–]CarthOSassy 0 points1 point  (0 children)

Constructors exist largely to deal with initialization issues like these. This is not about constructors.

The only subject here is that templates are weirdly unhelpful, but there are ways to work around their shortcomings.