今天在做数据库的时候 想到的这个问题
我该怎么通过占位符 去将这三个null赋进去
然后 我就开始实验
写了一个cul函数
public class ex {
public static void main(String agv[]){
System.out.println(Cul(1,null));
}
public static int Cul(int a,int b){
return a+b;
}
}
想法很美好 实际上报错
int类型的数据 首先默认为0 也就是说 null是无法使用的
根据查找资料 其实应该是用int的包装类Integer
然后 稍稍修改
public class ex {
public static void main(String agv[]){
System.out.println(cul(1,null));
}
public static int cul(Integer a,Integer b){
if(a!=null && b!=null) return a+b;
if(a==null) return b;
if(b==null) return a;
return 0;
}
}
成功编译~