0
public class Contract extends StandardEntity {
/***/
@Composition
@OnDeleteInverse(DeletePolicy.UNLINK)
@OnDelete(DeletePolicy.CASCADE)
@OneToMany(mappedBy = "contract")
protected List<Objective> objectives;
/***/

Is it possible to downgrade argument objectives in child class (ContractWthDeadLines extends Contract) from List< Objective> to List< ObjectiveWitchDeadLine>:

public class ObjectiveWitchDeadLine extends Objective
Ivan Baranuk
  • 185
  • 1
  • 13
  • Also, on an unrelated note, I assume that's supposed to be `WithDeadline`, not `WitchDeadline`. The latter to me implies potions and brooms and warts and things. – Joe C Jan 17 '18 at 08:09
  • No. You can not **downgrade** from List< Objective> to List< ObjectiveWitchDeadLine> or **upgrade** from List< ObjectiveWitchDeadLine> to List< Objective>. This can not compile. – xingbin Jan 17 '18 at 08:11
  • Thanks for answers. Unfortunately, generic SuperClass is not a solution and it is seems no way to do it without it. So i will figure out another way to solve that task. – Ivan Baranuk Jan 17 '18 at 09:06

1 Answers1

2

Make your Contract class generic

public class Contract<T extends Objective> extends StandardEntity {
   protected List<T> objectives;
}

and if you extend it you can change the type

public class ContractDeadline extends Contract<ObjectiveWitchDeadLine> {
}
homik
  • 553
  • 5
  • 9