Skip to content

Instantly share code, notes, and snippets.

@viveknaskar
Last active October 22, 2020 20:56
Show Gist options
  • Save viveknaskar/79a78af1ef984063d8b0b9676829be68 to your computer and use it in GitHub Desktop.
Save viveknaskar/79a78af1ef984063d8b0b9676829be68 to your computer and use it in GitHub Desktop.
Example to illustrate NullPointerException without using Optional
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