Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6740245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:34:59+00:00 2026-05-26T11:34:59+00:00

While browsing through some code for a library I’m using, I came across this

  • 0

While browsing through some code for a library I’m using, I came across this code snippet:

public class SomeClass {

     private static final class Null {
        /* ... */
     }

     public static final Object NULL = new Null();

}

Is this a common practice to have a special NULL object for a class that gets used instead of Java’s null? What are the upsides to doing this instead of using Java’s built in null?

The main reason I’m curious is that while using the library, I kept checking whether SomeClass was null, without realizing that they were using a special NULL object to denote a null object of SomeClass.

EDIT: For those wondering, the exact code from the source is:

public class JSONObject {
     private static final class Null {
        protected final Object clone() {
            return this;
        }
        public boolean equals(Object object) {
            return object == null || object == this;
        }
        public String toString() {
            return "null";
        }
    }

    public static final Object NULL = new Null();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:35:00+00:00Added an answer on May 26, 2026 at 11:35 am

    The null object pattern can occasionally be a useful one – so you don’t use a null reference, but have an actual object with neutral behaviour. However, the implementation you’ve given there doesn’t make sense:

    • Null doesn’t extend SomeClass, which I’d expect it to
    • NULL is declared as Object, not SomeClass.

    So as it is, I’d say that code is useless. But when implemented properly, the pattern can be useful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While browsing some code, I came across this line: if False: #shedskin I understand
While browsing I came across this blog post about using the Wikipedia API from
While browsing the code of an erlang application, I came across an interesting design
I found this code for a generic DAO interface while browsing around: public interface
I'm learning JavaScript and while browsing through the jQuery library I see : (colon)
While browsing some code I found a call to OpenPrinter() . The code compiles
While browsing the code of some websites I sometimes notice that some JavaScript files
While browsing through source code in my IDE I'll sometimes wish I could see
While browsing questions and answers in this forum i found a piece of code
While browsing through the source code of the java.util.concurrency package, I noticed an idiomatic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.