Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35579
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Changing accessor on public static class |
| Date | 2016-09-08 21:50 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <nqt4h1$1etf$1@gioia.aioe.org> (permalink) |
| References | (2 earlier) <nqnjl3$13g4$3@gioia.aioe.org> <734645c0-69c9-4ee2-a9c2-191b9f3710ab@googlegroups.com> <nqq5nk$vad$1@gioia.aioe.org> <6d2c31d9-1701-404e-b76d-1d1c6510a411@googlegroups.com> <nqssas$16ep$1@gioia.aioe.org> |
On 9/8/2016 7:30 PM, Arne Vajhøj wrote:
> I am saying that you should do different.
>
> Not:
>
> only if I need to use from static method use static
>
> But:
>
> only if I need direct access to enclosing instances data use non-static
>
> I am saying that you should change your default.
>
> Java chose a slightly misleading syntax.
>
> actual syntax: public static class Foobar
> better syntax: public class Foobar
>
> because:
> - it is really just a normal class with an unusual name
> - that is the syntax for the same semantics in C++ and C#
>
> actual syntax: public class Foobar
> better syntax: public verycompleximplicitrelationship class Foobar
>
> because:
> - that is what it is
> - it would discourage accidental usage
Just for the fun of it try figuring out this little program:
public class InnerSpagetti {
private int v;
public class InnerSpagettiHelp {
private int v;
public InnerSpagettiHelp(int v) {
this.v = v;
}
public void test() {
System.out.println(v - InnerSpagetti.this.v);
}
}
public InnerSpagetti(int v) {
this.v = v;
}
public InnerSpagettiHelp setup(InnerSpagetti o) {
return o.new InnerSpagettiHelp(v + 1);
}
public static void main(String[] args) {
InnerSpagetti o1 = new InnerSpagetti(10);
InnerSpagetti o2 = new InnerSpagetti(12);
InnerSpagettiHelp io1 = o1.setup(o2);
InnerSpagettiHelp io2 = o1.setup(o1);
io1.test();
io2.test();
}
}
Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Changing accessor on public static class mike <mikaelpetterson@hotmail.com> - 2016-09-06 00:53 -0700
Re: Changing accessor on public static class Alberto Salvati <zzzato@gmail.com> - 2016-09-06 01:12 -0700
Re: Changing accessor on public static class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-09-06 09:08 -0400
Re: Changing accessor on public static class Andreas Leitgeb <avl@logic.at> - 2016-09-06 23:00 +0000
Re: Changing accessor on public static class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-09-07 07:48 -0400
Re: Changing accessor on public static class Eric Douglas <e.d.programmer@gmail.com> - 2016-09-06 07:00 -0700
Re: Changing accessor on public static class Arne Vajhøj <arne@vajhoej.dk> - 2016-09-06 19:31 -0400
Re: Changing accessor on public static class Eric Douglas <e.d.programmer@gmail.com> - 2016-09-07 04:47 -0700
Re: Changing accessor on public static class Arne Vajhøj <arne@vajhoej.dk> - 2016-09-07 18:52 -0400
Re: Changing accessor on public static class Eric Douglas <e.d.programmer@gmail.com> - 2016-09-08 04:54 -0700
Re: Changing accessor on public static class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-09-08 08:38 -0400
Re: Changing accessor on public static class Eric Douglas <e.d.programmer@gmail.com> - 2016-09-08 06:35 -0700
Re: Changing accessor on public static class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-09-08 10:09 -0400
Re: Changing accessor on public static class Eric Douglas <e.d.programmer@gmail.com> - 2016-09-08 08:18 -0700
Re: Changing accessor on public static class Eric Douglas <e.d.programmer@gmail.com> - 2016-09-08 08:37 -0700
Re: Changing accessor on public static class Arne Vajhøj <arne@vajhoej.dk> - 2016-09-08 19:34 -0400
Re: Changing accessor on public static class Arne Vajhøj <arne@vajhoej.dk> - 2016-09-08 19:32 -0400
Re: Changing accessor on public static class Arne Vajhøj <arne@vajhoej.dk> - 2016-09-08 19:30 -0400
Re: Changing accessor on public static class Arne Vajhøj <arne@vajhoej.dk> - 2016-09-08 21:50 -0400
Re: Changing accessor on public static class Lew <lewbloch@gmail.com> - 2016-09-13 17:44 -0700
Re: Changing accessor on public static class Lew <lewbloch@gmail.com> - 2016-09-13 17:42 -0700
Re: Changing accessor on public static class Arne Vajhøj <arne@vajhoej.dk> - 2016-09-06 19:33 -0400
Re: Changing accessor on public static class Lew <lewbloch@gmail.com> - 2016-09-13 17:39 -0700
csiph-web