---
title: "Discussion on \"Dear Student, how to avoid null verifications in Java\" | Hashnode"
description: "Discussion on \"Dear Student, how to avoid null verifications in Java\". It is good programming practice, avoid null checking of a value, instead of using if (someObject! = Null), you can use Optional, it can be used as follows:\nOptional  oR = Optional.of (Optional.ofNullable (yourOriginalInstanceToUse) .orElse (YourInsta..."
url: "https://hashnode.com/posts/dear-student-how-to-avoid-null-verifications-in-java/618a69e5468c06249afc4ad2"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Dear Student, how to avoid null verifications in Java](https://andresdavidpastorini.hashnode.dev/dear-student-how-to-avoid-null-verifications-in-java?utm_source=hashnode&utm_medium=feed)

It is good programming practice, avoid null checking of a value, instead of using if (someObject! = Null), you can use Optional, it can be used as follows: Optional oR = Optional.of (Optional.ofNullable (yourOriginalInstanceToUse) .orElse (YourInsta...

Nov 9, 2021 · 1 min read · andresdavidpastorini.hashnode.dev  
Read the article

-   [#java](https://hashnode.com/tag/java)

## Written by

[Andres Pastorini](https://hashnode.com/@apastorini)

@apastorini · Montevideo

  
[View profile](https://hashnode.com/@apastorini)

Dear Student

## Responses 1

Markdown supported · ⌘↵ to post

[Shai Almog](https://hashnode.com/@talktotheduck)

[Nov 9, 2021](https://hashnode.com/posts/dear-student-how-to-avoid-null-verifications-in-java/618a69e5468c06249afc4ad2/comment/618a942b468c06249afc4f3f)

That's an option ;-)

Notice that optional isn't "free" and carries an [overhead on top of null](https://pkolaczk.github.io/overhead-of-optional/) .

It's not a big deal but personally [I like null](https://twitter.com/debugagent/status/1457664209446113285) .

[Andres Pastorini](https://hashnode.com/@apastorini)

[Nov 9, 2021](https://hashnode.com/posts/dear-student-how-to-avoid-null-verifications-in-java/618a69e5468c06249afc4ad2/comment/618a942b468c06249afc4f3f#reply-618aa277f991b025366dfe25)

Shai, You are right, it is true what you say, and thanks for share it.

I think if the performance is not important, Optional could be a good way, helping to reduce the size of the code and a interesting design pattern to improve the maintainability.
