gpt4 book ai didi

java - 当数组为 null 或空时如何抛出 IllegalArgumentException?

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

    /**
* This constructor accepts an array of points as input. Copy the points into the array points[].
*
* @param pts input array of points
* @throws IllegalArgumentException if pts == null or pts.length == 0.
*/
protected AbstractSorter(Point[] pts) throws IllegalArgumentException
{
try{
for(int i = 0; i < pts.length; i++)
{
points[i] = pts[i];
}
}
catch()
{

}
}

我知道这应该非常简单,但是在这些条件下我如何抛出这个异常?

最佳答案

protected AbstractSorter(Point[] pts) throws IllegalArgumentException
{
if(pts == null || pts.length ==0 )
throw new IllegalArgumentException();
for(int i = 0; i < pts.length; i++)
{
points[i] = pts[i];
}
}

关于java - 当数组为 null 或空时如何抛出 IllegalArgumentException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60581113/

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