Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33809
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: ... |
| Date | 2016-02-15 08:43 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <n9skg2$ggb$1@dont-email.me> (permalink) |
| References | <n9sdug$cej$6@reader1.panix.com> <n9shhp$5qe$1@dont-email.me> <n9sime$jvh$1@reader1.panix.com> |
On 2/15/2016 8:09 AM, Popping mad wrote:
> On Mon, 15 Feb 2016 07:52:56 -0500, Eric Sosman wrote:
>
>> ...
>
> is specifically what has me confused. Thanks.
>
> /* qualifiers */ Node[] children;
>
> not
> Node children[] ??
(For context, the question was about
public Node(Type type, Node... children) {
this.type = type;
this.children = children;
}
... and it now appears that the `Node... children' part is what
confuses the writer.)
This is a "variable arity" constructor (you can also write
methods the same way). It's a notational convenience that was added to
Java some, oh, leventy-three years ago or thereabouts. It allows you
to invoke the constructor (or method) with argument lists of different
lengths:
Node n3 = new Node(type3, child1, child2, child3);
Node n2 = new Node(type2, child1, child2);
Node n1 = new Node(type1, child1);
and even
Node n0 = new Node(type0);
Behind the scenes, what actually happens is that the constructor is
rewritten to the equivalent of
putlic Node(Type type, Node[] children) { ... }
and the calls turn into
Node n3 = new Node(type3, new Node[] {child1, child2, child3});
Node n2 = new Node(type2, new Node[] {child1, child2});
Node n1 = new Node(type1, new Node[] {child1});
and
Node n0 = new Node(type0, new Node[0]);
Note that this shorthand can only be used with a constructor or
method's *last* parameter; you can't write
void method(int n, String... s, double d) { ... }
or
void madness(int... n, String... s) { ... }
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
... Popping mad <rainbow@colition.gov> - 2016-02-15 11:48 +0000
Re: ... Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-15 07:52 -0500
Re: ... Popping mad <rainbow@colition.gov> - 2016-02-15 13:09 +0000
Re: ... Eric Douglas <e.d.programmer@gmail.com> - 2016-02-15 05:14 -0800
Re: ... Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-15 08:43 -0500
Re: ... Andreas Leitgeb <avl@logic.at> - 2016-02-15 13:46 +0000
Re: ... Eric Douglas <e.d.programmer@gmail.com> - 2016-02-15 06:03 -0800
Re: ... j4n bur53 <janburse@fastmail.fm> - 2016-02-15 15:54 +0100
Re: ... Eric Douglas <e.d.programmer@gmail.com> - 2016-02-15 07:24 -0800
Re: ... Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-15 11:08 -0500
Re: ... Arne Vajhøj <arne@vajhoej.dk> - 2016-02-15 11:17 -0500
Re: ... Andreas Leitgeb <avl@logic.at> - 2016-02-15 16:34 +0000
Re: ... Arne Vajhøj <arne@vajhoej.dk> - 2016-02-15 11:43 -0500
Re: ... Jan Burse <janburse@fastmail.fm> - 2016-02-15 20:44 +0100
Re: ... Jan Burse <janburse@fastmail.fm> - 2016-02-15 20:44 +0100
Re: ... Jan Burse <janburse@fastmail.fm> - 2016-02-15 20:45 +0100
Re: ... Andreas Leitgeb <avl@logic.at> - 2016-02-16 10:05 +0000
Re: ... Arne Vajhøj <arne@vajhoej.dk> - 2016-02-15 21:46 -0500
Re: ... Arne Vajhøj <arne@vajhoej.dk> - 2016-02-15 09:34 -0500
csiph-web