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?
- 开发者_开发知识库Does Java build some ready table for Parameters? Perhaps similar to Stdin argv[].
- 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) { ...
精彩评论