Re: Help -- New to Java
- From: Lew <lew@xxxxxxxxxxxxxxxx>
- Date: Thu, 26 Jul 2007 11:57:11 -0400
Bjorn Abelli wrote:
The main difference from C in this aspect is that you need to use the keyword "static". Otherwise it becomes an "instance member" instead of a "class member".No, you don't. This could just as well be an instance method.
Yes, he does, as his assignment explicitly says so... ;-)
You are correct. I was speaking outside the context of the OP's homework, wasn't I?
Actually, for methods the question of static vs. instance interests me. Is there a best practice (when a manager hasn't forced the choice for non-technical reasons)?
I lean towards making methods instance-level most of the time. For non-instantiable utility classes I use only static methods and no instance anythings.
Most of my instance methods are final (as their parameters usually are).
I figure this will give me the most power when I need to expand, secure or make thread-safe my classes, and doesn't carry a discernible penalty.
Some methods are inherently static, typically the sort that initialize an environment. If the design calls for it, that justifies it.
--
Lew
.
- Follow-Ups:
- Re: Help -- New to Java
- From: Bjorn Abelli
- Re: Help -- New to Java
- References:
- Help -- New to Java
- From: Al
- Re: Help -- New to Java
- From: Bjorn Abelli
- Re: Help -- New to Java
- From: Lew
- Re: Help -- New to Java
- From: Bjorn Abelli
- Help -- New to Java
- Prev by Date: Re: Help -- New to Java
- Next by Date: Re: Help -- New to Java
- Previous by thread: Re: Help -- New to Java
- Next by thread: Re: Help -- New to Java
- Index(es):
Relevant Pages
|