Re: Advantages of using private static methods in a class
- From: "andreas kinell" <news@xxxxxxxxx>
- Date: Sat, 31 Dec 2005 16:35:10 +0100
"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
.
- References:
- Advantages of using private static methods in a class
- From: HalcyonWild
- Advantages of using private static methods in a class
- Prev by Date: Re: Callbacks, and using interfaces as arguments
- Next by Date: Re: Creating a file in a directory
- Previous by thread: Advantages of using private static methods in a class
- Index(es):
Relevant Pages
|