Re: Advantages of using private static methods in a class




"HalcyonWild" <Halcyon.Wild@xxxxxxxxx> schrieb im Newsbeitrag
news:1136033388.437450.236210@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Hello all,
>
> I generally make small helper methods, private and static, inside my
> java class as , for example, below.
>
> //can use substring too, but this for example
> private static String getFirstCharacter(String str)
> {
> char [] c = str.toCharArray[];
> return ""+c[0];
> }
>
> I am having doubts if static methods is a good thing to do. Is it any
> better or worse, if I make the method non-static. Is this a good
> practice.
>
> I searched previous group posts on Google to find if this has been
> discussed before, but could not find it. (It returns almost all posts
> with private and static in them).
>
> What I understand is that the call is bound at compile time, if the
> method is marked as static, and therefore you can consider it as good
> as inline code. But I think I might be forgetting something, I am not
> sure. (I moved to Java programming about a year ago).
>
> I am going to read up more on that today, I thought I could have your
> opinions too.
>
> BTW, A very Happy New Year in advance. :)
>
> Thanks.

static or not should generally be a design issue rather than a performance
issue. This is true especially for larger applications. If the method
belongs to a class rather than an object, then make it static.
IMO, it is perfectly ok to make helper methods static.

andreas


.



Relevant Pages

  • Advantages of using private static methods in a class
    ... I generally make small helper methods, private and static, inside my ... java class as, for example, below. ... //can use substring too, but this for example ... I searched previous group posts on Google to find if this has been ...
    (comp.lang.java.help)
  • Re: Helper Methods
    ... I sometimes find it helpful to write private ... which in turn calls several private helper methods. ... Hmm, well no reason really, now that you mention it. ... nothing wrong with globals in that case, ...
    (comp.object)
  • Re: Helper Methods
    ... I sometimes find it helpful to write private ... which in turn calls several private helper methods. ... Hmm, well no reason really, now that you mention it. ... nothing wrong with globals in that case, ...
    (comp.object)