我试图将硬件组件添加到包含对象数组的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方法?
提前谢谢你
发布于 2020-04-02 14:15:23
方法签名是错误的public void placeComponent(<HardwareComponent> hw)。
尝试使用public void placeComponent(HardwareComponent hw)
https://stackoverflow.com/questions/60993541
复制相似问题