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 6240027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:29:37+00:00 2026-05-24T11:29:37+00:00

Sometimes when writing a class you’ll need some helper methods that take care of

  • 0

Sometimes when writing a class you’ll need some helper methods that take care of some simple stuff (change a string in a certain way or do some simple calculations).

If helper functionalities are small enough (and not needed by any other class) it makes sense to write a helper method in this class.

Now: assuming you’ll need no access to any member variables, would it be better do make this method private or private static

the following example: just implements a method that checks if a string is not null and contains foo.

public class SomeClass

...

 public void calculate(String inputString) {
  ...
  boolean foo = getFoo(inputString);
 }

 private (static) boolean getFoo(String inputString) {
  return inputString != null && inputString.contains("foo");
 }

}

Are there pros and cons in making the method static or non-static. Is there a general do and don’t?

  • 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-24T11:29:39+00:00Added an answer on May 24, 2026 at 11:29 am

    I would personally make the method static – it makes it clearer that it doesn’t depend on the state of the object. That can have knock-on effects in terms of thread safety (although if it were to access static members of the type, you’d need to be careful of that).

    Given that it’s private, you don’t need to worry about whether or not subclasses would want to override it.

    You can always make it non-static later – I think the only side-effect of that would be to potentially change the serialization ID. (Binary serialization is a pain like that.)

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

Sidebar

Related Questions

Sometimes while writing Java in Eclipse, I write code that generates warnings. A common
Sometimes I'm writing ugly if-else statements in C# 3.5; I'm aware of some different
I'm writing a JSP that sometimes needs to format a Java Date that comes
I'm writing a script for IRC and sometimes I might need to use a
When writing comments, I sometimes find myself needing to talk about a type (class,
I am (slowly) writing an XML parser for some site definition files that will
Unfortunately I've found that sometimes code I'm writing, while perfectly fine at run-time, causes
In my report, I'm writing some class names or variable names inside of a
I'm writing an app that sometimes requires very long-running DB requests. I'd like to
I have a call to TraceSource.TraceEvent() that is sometimes not writing to the Azure

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.