gpt4 book ai didi

java - PCB 类型中的方法 placeComponent() 不适用于参数 (HardwareComponent)

转载 作者:行者123 更新时间:2023-12-02 08:47:15 25 4
gpt4 key购买 nike

我正在尝试将硬件组件添加到包含对象数组的 PCB,但我无法将对象传递到数组。这是我的第一个 Java 项目,所以这里完全是新手。请帮忙!

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);
}

还有我的主要内容

 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);

我收到此错误:PCB 类型中的方法 placeComponent() 不适用于参数 (HardwareComponent)

不知道从这里开始,我是否需要为 PCB 类创建一个单独的构造函数,或者如何将 HardwareComponent 传递给方法 placeComponent?

提前谢谢

最佳答案

方法签名错误 public void placeComponent(<HardwareComponent> hw) .
尝试用 public void placeComponent(HardwareComponent hw)

关于java - PCB 类型中的方法 placeComponent() 不适用于参数 (HardwareComponent),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60993541/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com