-2

I have an interface VersionInterface which is implemented by my object ObjectDefinition

I also have a method that accepts two List<VersionInterface> as arguments.

Since ObjectDefinition implements VersionInterface, why can't I pass my two List<VersionInterface>as arguments to my method?

Method Definition:

public List<VersionInterface> updateArtifact(List<VersionInterface> currentCopy, List<VersionInterface> updatedCopy)

ObjectDefinition Definition:

public class ObjectDefinition implements VersionInterface {

How I'm calling updateArtifact:

service.updateArtifact(currentCopy, updatedCopy);

currentCopy and updatedCopy are both ArrayList<ObjectDefinition>

I get:

The method updateArtifact(List<VersionInterface>, List<VersionInterface>) in the type ORService is not applicable for the arguments (List<ObjectDefinition>, List<ObjectDefinition>)

Edit: My problem has to do with interfaces and not subclasses

Fueled By Coffee
  • 2,467
  • 7
  • 29
  • 43

1 Answers1

-1

You can't do that because the method prototype specifies that it's returning a List of VersionInterface objects, not a List of ObjectDefinition objects.

VersionInterface is an Interface, as you've demonstrated. Maybe ObjectDefinition is the only class that implements that interface, but in general that is not the case in Java. There could be multiple implementations of VersionInterface, and the List that is returned may contain objects of various different types.

nasukkin
  • 2,460
  • 1
  • 12
  • 19