[
http://issues.ops4j.org/jira/browse/QI-53?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_11482
]
Rickard Öberg commented on QI-53:
---------------------------------
Of course that should be: "Look at jira.qi4j53.IssueTest..."
> Exception when trying to declare a property with a generic type and a
> constraint
> --------------------------------------------------------------------------------
>
> Key: QI-53
> URL: http://issues.ops4j.org/jira/browse/QI-53
> Project: Qi4j
> Issue Type: Bug
> Components: Core Runtime
> Affects Versions: 0.2
> Reporter: Richard Wallace
> Assignee: Rickard Öberg
> Fix For: 0.3
>
>
> (First reported in thread on mailing list
> http://lists.ops4j.org/pipermail/qi4j-dev/2008-May/002094.html)
> I'm trying to create a composite called CostPerUnit with the Amount,
> Money, and Unit classes that are part of JSR-275 and JScience. It looks
> like this
> public interface CostPerUnit {
>
> @NotNull ImmutableProperty<Amount<Money>> cost();
> @NotNull ImmutableProperty<Unit<?>> unit();
> CostPerUnit toCostPer(@NotNull Unit<?> unit);
> }
> then my mixin that implements the toCostPer(unit) method is
> public abstract class CostPerUnitMixin implements CostPerUnit {
> @This CostPerUnit costPerUnit;
> @Structure CompositeBuilderFactory builderFactory;
>
> public @Cached CostPerUnit toCostPer(Unit<?> unit) {
> CompositeBuilder<CostPerUnitComposite> builder =
> builderFactory.newCompositeBuilder(CostPerUnitComposite.class);
>
> builder.stateOfComposite().cost().set(convert(costPerUnit.cost().get(),
> costPerUnit.unit().get(), unit));
> builder.stateOfComposite().unit().set(unit);
> return builder.newInstance();
> }
>
> Amount<Money> convert(Amount<Money> cost, Unit<?> from, Unit<?> to) {
> UnitConverter converter = from.getConverterTo(to);
> return
> Amount.valueOf(converter.convert(cost.getEstimatedValue()), cost.getUnit());
> }
> }
> and then I have a composite defined as
> @Mixins({CostPerUnitMixin.class})
> public interface CostPerUnitComposite extends CostPerUnit, Composite {}
> So naturally I wanted to test the conversion was working - I don't
> really expect it to be but that's what the test is for. But when I try
> and run the test I get the following exception
> java.lang.ClassCastException:
> sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be
> cast to java.lang.Class
> at
> org.qi4j.spi.composite.CompositeModel.getConstraintModel(CompositeModel.java:215)
> at
> org.qi4j.runtime.composite.CompositeResolver.addConstraintResolution(CompositeResolver.java:429)
> at
> org.qi4j.runtime.composite.CompositeResolver.resolvePropertyModel(CompositeResolver.java:419)
> at
> org.qi4j.runtime.composite.CompositeResolver.resolveMixin(CompositeResolver.java:152)
> at
> org.qi4j.runtime.composite.CompositeResolver.getResolvedMixins(CompositeResolver.java:223)
> at
> org.qi4j.runtime.composite.CompositeResolver.resolveCompositeModel(CompositeResolver.java:69)
> If I take out the Amount<Money> and replace it with a Long and then take
> out the unit property, the CompositeBuilder is able to create a
> CostPerUnitComposite instance just fine.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.ops4j.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev