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

  • SEARCH
  • Home
  • 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 173137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:17:24+00:00 2026-05-11T13:17:24+00:00

Static utility methods are generally frowned up by OO purists. I was wondering however

  • 0

Static utility methods are generally frowned up by OO purists.

I was wondering however what people feel about utility methods that are used to avoid something simple like a null check throughout the application.

String.trim() throws a NPE when invoked on a null String. So I have to do:

if(str!=null)       setValue(str.trim()); else      setValue(''); 

What if I create a utility method that checks for the null?

setValue(myTrim(str));  public static String myTrim(String str) {    if(str==null) return ''     else return str.trim(); } 

The one problem I have encountered with methods like these is that some developers on the team might not like/not know this utility and might be doing staight calls after doing a null comparison.

Is this something that you do your framework too? If yes, what are the other common utility general use methods that people have created and are using in their applications?

What do you feel are the pros and cons of either approach?

  • 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. 2026-05-11T13:17:25+00:00Added an answer on May 11, 2026 at 1:17 pm

    I’d be inclined to replace the homegrown uses when an existing library (like Apache Commons Blah Blah Blah) already has written it. Code you can offload to someone else lets you focus on the important parts of the software that truly differentiate your work from everyone else’s. But yes, utility classes with static methods are great, if they need to be written by you at all.

    FYI, take a look at StringUtils.trimToEmpty(). Good luck.

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

Sidebar

Related Questions

I have a static methods class, Utils, that is basically for utility methods, its
I have some custom classes that just contain static utility methods: app/Lib/Utility/AppString.php Cake can't
What's the difference in Java between a utility class (a class with static methods)
I have a class that consists only of static member variables and static methods.
I'm using some classes and several utility methods that use std:: vector. Now I
ReSharper sometimes hints that I can make some of my random utility methods in
I find that when using java collections, especially when writing utility methods using generics,
I'm looking for some pros and cons for using extension methods over static utility
I'm wondering if it is a good style to inject utility methods with google
I need to add a method in a utility class with some static methods

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.