Search code examples
javaandroidobjecttype-conversionprimitive

Assigning long to Long in Java


I am currently going through one of the Android Tutorials. I found an expression like:

Bundle bundle = getIntent().getExtras();
Long longVariable = bundle.getLong(someId);
if( longVariable != null )
{
  //doSomething
}

After looking at Bundle.getLong in the API I saw that it returns a long (primitive). Now, I didn't write Java for quite a while, only C# in the meanwhile, but how can the object Long longVariable variable ever be null?


Solution

  • If getLong() really has return type long it can't be, i.e. l will never be null. Probably the programmer didn't look up the return type, but inferred from the method name a Long would be returned.