-1

ABTeacher and ABStudent is child class of ABUser

And in applyStudentChange I have Collection<ABStudent> ABStudents

I want to call changeABUser(Collection<ABUser> ABUsers) in applyStudentChange but the collection I have got is a collection of child class, how should I call changeABUser(Collection<ABUser> ABUsers) ?

I tried call this waychangeABUser((Collection<ABUser>) ABStudents), and this cast does not seem to work...

KKlalala
  • 965
  • 1
  • 13
  • 23
  • Possible duplicate of [What is PECS (Producer Extends Consumer Super)?](https://stackoverflow.com/questions/2723397/what-is-pecs-producer-extends-consumer-super) – Lino May 21 '18 at 20:08

1 Answers1

0

You need to give the following member type for your collection:

.... changeABUser(Collection<? extends ABUser> users) ....
Ingo
  • 36,037
  • 5
  • 53
  • 100
  • No. The method `changeABUser` needs to take a `Collection extends ABUser>` that is: a collection whose member type is ABUser or a subtype thereof. – Ingo May 21 '18 at 20:14