-2
我有一个存储其他对象的通用数组类。当我尝试从泛型数组中获取对象值时,它会打印插入对象类路径。我如何获取价值?获取通用数组中的对象而不是类路径的值
public class Shop implements Initializable {
@FXML private TextField name;
@FXML private TextField quantity;
@FXML private TextArea list;
MyArrayList<Item> array = new MyArrayList<>();
@Override
public void initialize(URL location, ResourceBundle resources) {
}
@FXML
private void addItem() {
int q = Integer.parseInt(quantity.getText());
String n = name.getText();
Item item = new Item(n,q);
MyArrayList.getInstance().add(item);
System.out.println(MyArrayList.getInstance().getItem(0));
//Outputs [email protected] instead of the value Banana.
}
'的System.out.println(MyArrayList.getInstance()的getItem(0).getName());'。如果没有'getName()'方法,请添加一个。 – NAMS
它说“无法解决方法”。我在Item类中有一个getName()方法,但我无法通过MyArrayList类访问它。 – mattesj
'System.out.println(MyArrayList.getInstance()。getItem(0).getClass()。getN ame());' –