开发者

Java: prebuild flag to check pars not NULLs?

开发者 https://www.devze.com 2022-12-28 18:58 出处:网络
Currently, I use a very conservative way to stop malfunctioing code. It is annoying at the time of a change when I have to change the checker parts as well.

Currently, I use a very conservative way to stop malfunctioing code. It is annoying at the time of a change when I have to change the checker parts as well.

            if(ds==null||s==null||maxDs==null)
            {
                    System.out.println("NULL in getDirs(ds[],s,maxDs)");
                    System.exit(9);
            }

So is there some prebuild-ready Null checker for pars in the API?

  1. 开发者_开发知识库Does Java build some ready table for Parameters? Perhaps similar to Stdin argv[].
  2. If so, where can I find all automatically build tables like argv[]?

Wanna-check-for-parameters

for(Object p:pars)
{
    if(p.isNull())
    {
       System.out.println("Lollipop arg your pars are in Lava!");
       System.exit(9);
    }
}


I'm not aware of anything built in, but it should be possible to write your own annotation processet to inject some suitable code. It seems possible that only some methods need a null check, so having the control that annotations would give could be useful.

@ParamNotNull
public void myMethod(X anX, Y aY) { ...


public void myTolerantMethod(X couldbeNull) { ...
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号