Hello Timothy,

Thanks for the response! So since this is supposed to work (I wasn't
sure given that only OSGi 4.3
begins to introduce generics), I will look into this a bit more.

thanks again,
Gareth

On Tue, Oct 11, 2011 at 8:12 AM, Timothy Ward <[email protected]> wrote:
> Hi,
>
> I would expect this to work, have you tried specifying index parameters for
> the constructor arguments?
>
> Also, it would be worth opening a JIRA with some failing example code
> attached (unless of course you want to supply some tests and a fix :)).
> Blueprint gets fairly regular attention from the committers, so I imagine a
> JIRA will get dealt with reasonably quickly.
>
> Regards,
>
> Tim
>
>> Date: Mon, 10 Oct 2011 12:54:42 -0400
>> Subject: Generics And Aries Blueprint
>> From: [email protected]
>> To: [email protected]
>>
>> Hello,
>>
>> Is injection using java 5 generics allowed?
>>
>> My scenario - I am creating two generic classes:
>>
>> public class MyClass1<V extends MyBaseClass> implements Runnable {
>> public MyClass1(long myArgument) {
>> }
>> }
>>
>> -----
>> public class MyClass2<E extends MyBaseClass> implements MyInterface<E> {
>> // just using default constructor
>> }
>>
>> which I want to insert into another class:
>>
>> public class MyClass3 {
>> public MyClass3(MyClass1<MyImplementationClass> myClass1,
>> MyInterface<MyImplementationClass> myInterface) {
>> }
>> }
>>
>> In my blueprint file I have:
>>
>> <bean id="myClass1" class="com.mycompany.MyClass1"
>> init-method="start" destroy-method="stop">
>> <argument value="5000" />
>> </bean>
>>
>> <bean id="myClass2" class="com.mycompany.MyClass2" />
>>
>> <bean id="myClass3" class="com.mycompany.MyClass3" >
>> <argument ref="myClass1"/>
>> <argument ref="myClass2"/>
>> </bean>
>>
>> If I run this as is, blueprint will throw the following exception:
>>
>> org.osgi.service.blueprint.container.ComponentDefinitionException:
>> Unable to find a matching constructor on class com.myCompany.myClass3
>> for arguments [com.mycompany.MyClass1@787f7957,
>> com.mycompany.MyClass2@66525531] when instanciating bean myClass3
>> at
>> org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:272)[31:org.apache.aries.blueprint:0.3.1]
>> at
>> org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:706)[31:org.apache.aries.blueprint:0.3.1]
>> at
>> org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:64)[31:org.apache.aries.blueprint:0.3.1]
>> at
>> org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:219)[31:org.apache.aries.blueprint:0.3.1]
>> at
>> org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:147)[31:org.apache.aries.blueprint:0.3.1]
>> at
>> org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:640)[31:org.apache.aries.blueprint:0.3.1]
>> at
>> org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:331)[31:org.apache.aries.blueprint:0.3.1]
>> at
>> org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:227)[31:org.apache.aries.blueprint:0.3.1]
>> at
>> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)[:1.6.0_26]
>> at
>> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)[:1.6.0_26]
>> at java.util.concurrent.FutureTask.run(FutureTask.java:138)[:1.6.0_26]
>> at
>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)[:1.6.0_26]
>> at
>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)[:1.6.0_26]
>> at
>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)[:1.6.0_26]
>> at
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)[:1.6.0_26]
>> at java.lang.Thread.run(Thread.java:680)[:1.6.0_26]
>>
>> If I remove the generic specification from the MyClass3 constructor,
>> everything works OK:
>>
>> public class MyClass3 {
>> public MyClass3(MyClass1 myClass1, MyInterface myInterface) {
>> }
>> }
>>
>> Is that what is supposed to happen? Am I not allowed to use generics
>> in constructor arguments?
>>
>> thanks in advance,
>> Gareth
>

Reply via email to