android - Java vs Objective C in case of nullpointer exception -


why java throw null pointer exception if try access null values while objective c not?

java:

public class subscribeemailactivity {     string status;      public static void main(string[] args){          if(status.equals(null)||status.equals(""){              // getting error here          }      }  } 

objective c:

//in .h file nsstring *exp;  //in .m file if ([exp isequaltostring:null] ||[exp isequaltostring:@""]) {     // not getting error } 

ultimately, way solve problem using different programming language:

  • in objective-c, can equivalent of invoking method on nil, , absolutely nothing happen. makes null checks unnecessary can make errors harder diagnose.
  • in nice, java-derivated language, there 2 versions of types: potentially-null version , not-null version. can invoke methods on not-null types. potentially-null types can converted not-null types through explicit checking null. makes easier know null checks necessary , aren't.

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -