java - How do I Override a Iterable<interface> return type method into Iterable<? extends interface> return type method -
i have interface need implement. looks this:
public interface simulationstate { ... public iterable<vehiclestatus> getvehiclestatuses(); }
i trying extend interface sort of decorator interface following:
public interface simulationstatedec<v extends vehiclestatus> extends simulationstate { ... @override public iterable<v> getvehiclestatuses(); }
or
public interface simulationstatedec<v extends vehiclestatus> extends simulationstate { ... @override public iterable<? extends vehiclestatus> getvehiclestatuses(); }
here's concrete class i'm implementing interface at:
public class warehousestate implements simulationstate { ... @override public iterable<vehiclestatus> getvehiclestatuses() { return this.vstatuses; } }
i implementing vehiclestatus interface @ class named vehiclestate return implemented vehiclestate though iterable in concrete class
so @ class in project calling getvehiclestatuses()
method , obligated cast every element vehiclestate following:
public class gate { ... private arraylist<vehiclethread> vehicles; public gate(warehouse warehouse, gatepriority priority) { ... this.vehicles = new arraylist<>(); warehousestate.getvehiclestatuses().foreach(v -> vehicles.add(new vehiclethread((vehiclestate) v, warehouse))); sortsametimearrivalby(priority); } }
i know doing wrong here, wondering if way of implementation allowed. compiler tells me change method in implemented interface , it's not applicable application has work on different framework.
i need return variety of concrete types implements same interface without having cast every element.
this how should use it, since x< a> not substitutable x< b > though extends b, put iterable< vehiclestatus> not replaceable iterable< v> v extends vehiclestatus.hence, error changing method return type while overriding
public class vehiclestatus{ } public interface simulationstate { iterable<? extends vehiclestatus> getvehiclestatuses(); } public interface simulationstatedec<v extends vehiclestatus> extends simulationstate { @override public iterable<v> getvehiclestatuses(); }
Comments
Post a Comment