The method placeComponent() in the type PCB is not applicable for the arguments (HardwareComponent)

Sean O ́ :

I'm trying to add Hardware Components to a PCB which contains arrays of objects and I am not able to pass the object to the array. This is my first Java Project so total newbie here. Please Help!

public class PCB {
    private Collection<HardwareComponent> hwComponents = new Vector<HardwareComponent>();
    private Collection<CircuitPath> connections = new Vector<CircuitPath>();

    public void placeComponent(<HardwareComponent> hw) {
        hwComponents.add(hw);
    }

And my Main

 public class Configurator {

    public static void main(String[] args) {

        PCB pcb = new PCB();

        HardwareComponent c1 = new Capacitor("cap1", 0.55f);
        HardwareComponent c2 = new Capacitor("cap2", 0.22f);
        HardwareComponent c3 = new Capacitor("cap3", 0.50f);
        HardwareComponent c4 = new Capacitor("cap4", 0.75f);
        HardwareComponent r1 = new Resistor("res1", 0.14f);
        HardwareComponent r2 = new Resistor("res2", 0.18f);
        HardwareComponent r3 = new Resistor("res3", 0.17f);
        HardwareComponent r4 = new Resistor("res4", 0.10f);

        pcb.placeComponent(c1);

I'm getting this error: The method placeComponent() in the type PCB is not applicable for the arguments (HardwareComponent)

No idea where to go from here, do I need to make a separate constructor for the class PCB or how do I pass the HardwareComponent to the method placeComponent?

Thank you in advance

Traian GEICU :

The method signature is faulty public void placeComponent(<HardwareComponent> hw).
Try with public void placeComponent(HardwareComponent hw)

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=388910&siteId=1