Consider the following codeString s=null; Which code fragments cause an object of type NullPointerException to be thrown
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:
- s.length();
- int length = s.length();
- if (s.equals("hello")) { // do something }
- int hashCode = s.hashCode();

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