A simple NULL killer.

You know what it’s like – you want to avoid nulls. Well this is part of my utilclasses package. Along with the “optional” package. This simple routine is a one line call to ensure I never get a null back.

To call It I simply do

String stringTest=null;
Integer numTest=null;
System.out.println(noNulls.fix(stringTest));
System.out.println(noNulls.fix(numTest));

Here’s the class.

package utilclasses;
/**
 * 
 * Another fine Java Class
 * http://www.netbeansboy.org
 * @author paulc
 */
public abstract class noNulls {

public final static Object fix(Object value) {
 if (value==null) {
     if (value instanceof String) return "";
     return 0;
     }
 return value;
 }
 
}
Advertisements

About Paul C

I am a Senior Java programmer/Web Technologies, Play in a band called Mandolin Monday, I have a cat and I live on a boat.

Posted on August 14, 2015, in Uncategorized. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: