gpt4 book ai didi

java - 整数 null 以检查数据库

转载 作者:行者123 更新时间:2023-12-02 05:22:40 25 4
gpt4 key购买 nike

例如,我有这个简单的构造函数:

public Car(String brand, String model, int price){
this.brand=brand;
this.model=model;
this.price=price;
}

所以,我需要创建对象来检查数据库:

new Car (null, null, 15000);
new Car (Opel, null, null);

在第一种情况下我没有问题,但在第二种情况下,不允许整数值为空。

有什么建议吗?

谢谢!

最佳答案

您可以使用一些默认值(例如 -1)来表示 null,或者使用可以为 null 的 Integer,而不是 int

关于java - 整数 null 以检查数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26373578/

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