Last active
October 22, 2020 20:56
-
-
Save viveknaskar/79a78af1ef984063d8b0b9676829be68 to your computer and use it in GitHub Desktop.
Example to illustrate NullPointerException without using Optional
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.viveknaskar; | |
public class ExampleWithoutOptional { | |
public static void main(String[] args) { | |
String[] cities = new String[10]; | |
/** | |
* The array is empty is empty. | |
* No null check has been done, it will throw NullPointerException | |
*/ | |
String city = cities[5].toLowerCase(); | |
System.out.println(city); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment