开发者

Java: prebuild flag to check pars not NULLs?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜