Java Pearls: the Void class

Browsing through project code for clean up has let us stumble upon this:

package some.pkg;
public class Void4MyProject implements Serializable{
  public static final Void4MyProject NULL = null;
  private Void4MyProject() {

I never had the need to have a serializable null-instance. Simply beautifull and creative.

Just for playing… how is it used…

  final protected IAccessor subTable() {
    return new IAccessor() {
      public String getId() {
        return SUB_TABLE;
      public Class getStaticType() {
        return Void4MyProject.class;
      public Void4MyProject getValue(T parent) {
        return null;
      public void setValue(T parent, Void4MyProject value) {
        // nothing to do

Here I consider it a big NoNo that the defined instance of Void4MyProject is not even used.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s