Any code fragment that attempts to call a method or access a property of the variable s will cause a NullPointerException to be thrown because s has not been initialized to reference any object. For example:

  1. s.length();
  2. int length = s.length();
  3. if (s.equals("hello")) { // do something }
  4. int hashCode = s.hashCode();
Consider the following codeString s=null; Which code fragments cause an object of type NullPointerException to be thrown

原文地址: http://www.cveoy.top/t/topic/bRE3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录