Why this interface casting does not work?

Viewed 18

I need a little bit of help on how to work correctly with java interfaces.

I have an ArrayList with the implementation of a certain interface.

private ArrayList<ServiceClassImpl> services;

The manager class also implements an interface in which is a method who should return an ArrayList with the interface of the ServiceClass Impl

@Override
public List<IService> getAllServices() {
    return this.services;
}

Problem is that this does not work and I dont know why. With a single object it does work.

private ServiceClassImpl service;


public IService getService() {
       return this.service;
}

I don't understand it. Thanks for your help :)

0 Answers
Related