作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将硬件组件添加到包含对象数组的 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/
我正在尝试将硬件组件添加到包含对象数组的 PCB,但我无法将对象传递到数组。这是我的第一个 Java 项目,所以这里完全是新手。请帮忙! public class PCB { private
我是一名优秀的程序员,十分优秀!