Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #26250
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: static data for methods... |
| Date | Wed, 9 Oct 2013 15:29:31 +0000 (UTC) |
| Organization | A noiseless patient Spider |
| Lines | 50 |
| Message-ID | <slrnl5atis.mol.avl@gamma.logic.tuwien.ac.at> (permalink) |
| References | <slrnl5ape4.mol.avl@gamma.logic.tuwien.ac.at> <static-20131009162854@ram.dialup.fu-berlin.de> |
| Reply-To | avl@logic.at |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Wed, 9 Oct 2013 15:29:31 +0000 (UTC) |
| Injection-Info | mx05.eternal-september.org; posting-host="5a59604bffc0f9a3bccb75d244f116a9"; logging-data="22355"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/mstoTPWKDlSO7ZQ+jcE2Y" |
| User-Agent | slrn/pre0.9.9-111 (Linux) |
| Cancel-Lock | sha1:YIGfJGhi8VIll/beD9F7rfI/v6I= |
| Xref | csiph.com comp.lang.java.programmer:26250 |
Show key headers only | View raw
Stefan Ram <ram@zedat.fu-berlin.de> wrote:
> Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> writes:
>> I'm aware that in Java, methods cannot have static data within
>> them.
> You can encapsulate both in a class that consists just of
> the static data and this single method. Actually, that's
> how classes came up in Simula IIRC.
Probably that's be the optimum of what's available. Thanks!
>> However, I need the static fields lexically separated for the
>> methods.
> What is this lexical separation? I do not know this term.
It's that two methods fuBar() and snaFu() both might need their
own static "foo" field (and both want it by that exact name, because
the real name is really something meaningful, not "foo") and that
fuBar()'s "foo" must be a separate thing from e.g. snaFu()'s "foo".
Btw., that's perfectly well handled with your suggestion.
> Your class name contains the letter »f«, ...
I thought it would be obvious, that code samples in newsgroups using
names from the list: foo, bar, baz, snafu, fubar
are typically not taken exactly from real code, but placeholders for
variable names that contain domain-language. (I'm not ruling out that
people might name variables like that even in real code, but it's just
not the one thing to assume generally.)
I assure you, that the methods and variables in my actual code
DO include non-english words starting with "f", but neither from
the above list, nor that "f"-word that foo and fubar were derived
from, nor other derivations of that word.
> So, what's wrong with
> final class counter
> { static int field = 0;
> static int next(){ return field++; }}
Nothing's wrong. It's the suggestion you made at the top
of your post and I think I'll actually take that approach.
Btw., I'll make class "counter" static and also create a trivial
wrapper-method for "next()" in the toplevel class, so the method
can later be called from other (similarly wrapped) methods of that
toplevel class. (I'm also expecting that the extra call-level will
be a piece of cake for the JIT to optimize away later.)
Thanks a lot!
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
static data for methods... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-10-09 14:18 +0000
Re: static data for methods... taqmcg@gmail.com - 2013-10-09 07:49 -0700
Re: static data for methods... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-10-09 15:42 +0000
Re: static data for methods... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-10-09 15:29 +0000
Re: static data for methods... Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-10-10 14:44 +0200
Re: static data for methods... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-10-10 13:13 +0000
Re: static data for methods... Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-10-10 15:44 +0200
Re: static data for methods... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-10-10 17:26 +0000
Re: static data for methods... Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2013-10-11 22:03 -0700
Re: static data for methods... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-10-18 15:31 +0000
csiph-web