You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@reef.apache.org by Dhruv Mahajan <dh...@gmail.com> on 2015/09/12 22:46:14 UTC

Issues of instantiation of class with duplicate entries

Suppose I have a class with two generic types public class A<T1,T2> and let
ICodec<T> be an interface. Now assume class has injectable constructor:

[inject]
A(ICodec<T1>,ICodec<T2>)

Now if T1 is not same as T2 we are fine. But say T1=T2=int. In this case
instantiation will fail with duplicate entries. Now one can use
NamedParameters but my understanding is that they are only for basic types
like int,string etc. Is my understanding correct. If yes is there any other
way except declaring two wrappers that wrap them.

Dhruv

Re: Issues of instantiation of class with duplicate entries

Posted by Markus Weimer <ma...@weimo.de>.
On 2015-09-12 13:46, Dhruv Mahajan wrote:
> [inject] A(ICodec<T1>,ICodec<T2>)
> 
> [...] But say T1=T2=int. In this case instantiation will fail with
> duplicate entries.

What is the exception you are getting? I don't see why this couldn't be
made to "just work".

> Now one can use NamedParameters but my understanding is that they are
> only for basic types like int,string etc. Is my understanding
> correct.

No. `Name<T>` can be used when T is something other than data types. We
have many examples in the code where it is used for `ISet<T2>`, with T2
being some event handler, for instance.

Markus