Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java代码检查将null返回方法显示为never null_Java_Android_Android Studio_Lint - Fatal编程技术网

Java代码检查将null返回方法显示为never null

Java代码检查将null返回方法显示为never null,java,android,android-studio,lint,Java,Android,Android Studio,Lint,我发现了一个有趣的线头检查,我无法解释。我知道Java疯狂隐藏的东西,所以我想了解这里发生了什么。也许我可以用超级书呆子的知识打动我的朋友 下面是一段有问题的代码: public void awesomeMethod() { final int[] hungryPeople = getHungryPeople(); if ( hungryPeople != null ) // <---- Lint says that this can never be null?

我发现了一个有趣的线头检查,我无法解释。我知道Java疯狂隐藏的东西,所以我想了解这里发生了什么。也许我可以用超级书呆子的知识打动我的朋友

下面是一段有问题的代码:

public void awesomeMethod()
{    
    final int[] hungryPeople = getHungryPeople();

    if ( hungryPeople != null ) // <---- Lint says that this can never be null?
    {
         solveWorldHunger( true );
         tellEveryone( false );
    }
}

这里缺少什么吗?

如果
null
,则需要在
gethungryopele()
内部返回

public int[] getHungryPeople()
{
   // Get hungry people data from the class's Android Intent field
   final int[] values = mIntent.getIntArrayExtra( HUNGRY_PEOPLE );

   if ( null != values )
   {
        return Arrays.copyOf( values, values.length );
   }

   // if values is null, return null
   return null;
}

IDE应该为GetHungryOple()报告错误;如果value==null,则不返回任何内容。
public int[] getHungryPeople()
{
   // Get hungry people data from the class's Android Intent field
   final int[] values = mIntent.getIntArrayExtra( HUNGRY_PEOPLE );

   if ( null != values )
   {
        return Arrays.copyOf( values, values.length );
   }

   // if values is null, return null
   return null;
}