Why can't we cast org.eclipse.lyo.client.oslc.resources.Requirement to a subclass extending Requirements class?
Hi All,
I am trying to downcast Requirements class, using the below code : Requirement otherRequirement = new MyRequirements(); otherRequirement = getResponse.getEntity(Requirement.class); // Load response in a Requirement object ((MyRequirements)otherRequirement).addCRSSatisfiedBySysRS(new Link(new URI("Some Url"))); But at the time of downcasting using the below line : ((MyRequirements)otherRequirement).addCRSSatisfiedBySysRS(new Link(new URI("Some Url"))); I get org.eclipse.lyo.client.oslc.resources.Requirement cannot be cast to org.XXX.samples.MyRequirements, MyRequirements here is my sub class that extends the Requirement class. I am pretty sure the downcasting works with other codes, but it gives an error here. Is there anything in particular with the Requirement class? |
Accepted answer
Anuraj,
I know this is an old topic, but maybe this will help someone else.
First, in Java you can only cast MyRequirements to Requirement, not the other way around. Google for Covariance and Contravariance In Java to read more about this.
Second, support for unmarshalling subclasses was added recently to Lyo: https://github.com/eclipse/lyo.core/pull/29
Cheers,
Andrew
(Eclipse Lyo project lead)
David Lafreniere selected this answer as the correct answer
|
One other answer
Ralph Schoon (63.6k●3●36●46)
| answered Jul 26 '16, 7:46 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
You might want to ask in the Oslc forum http://open-services.net/forums/ as this question seems to be around Lyo and not doors next.
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.