Given:
and
and
and
What needs to change to make these classes compile and still handle all types of Interface Worker?
Given:
and
and
and
What needs to change to make these classes compile and still handle all types of Interface Worker?
The issue lies in the generic type bounds and method parameter types. The class Main<T extends Worker> is designed to handle any type that implements the Worker interface. However, the method addProcess(HardWorker w) specifically requires an instance of HardWorker, which contradicts the flexibility offered by the generic type T. To make the class generic and compatible with any Worker, the parameter type in the addProcess method should be changed to Worker. This ensures that the processes list can hold any type of Worker, fulfilling the intended purpose of handling all types that implement the Worker interface. Therefore, replacing Line 3 with public void addProcess(Worker w) { solves the issue.
Tested D is ok
d is ok
Tested: D.
Answer: D
D is correct replace line 3 with public void addProcess(T w) {