Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33803 > unrolled thread
| Started by | Popping mad <rainbow@colition.gov> |
|---|---|
| First post | 2016-02-15 11:48 +0000 |
| Last post | 2016-02-15 09:34 -0500 |
| Articles | 19 — 7 participants |
Back to article view | Back to comp.lang.java.programmer
... 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
| From | Popping mad <rainbow@colition.gov> |
|---|---|
| Date | 2016-02-15 11:48 +0000 |
| Subject | ... |
| Message-ID | <n9sdug$cej$6@reader1.panix.com> |
can someone tell me exactly what a constructor like this does?
public Node(Type type, Node... children) {
this.type = type;
this.children = children;
}
[toc] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2016-02-15 07:52 -0500 |
| Message-ID | <n9shhp$5qe$1@dont-email.me> |
| In reply to | #33803 |
On 2/15/2016 6:48 AM, Popping mad wrote:
> can someone tell me exactly what a constructor like this does?
>
> public Node(Type type, Node... children) {
> this.type = type;
> this.children = children;
> }
We can infer that the class has fields named `type' and
`children', declared in a manner something like
/* qualifiers */ Type type;
/* qualifiers */ Node[] children;
... where /* qualifiers */ may involve things like `private',
`protected', `public', `final', `transient', and so on. (Maybe
even `static', although that would be unusual.) The constructor
sets the class' fields equal to its parameters, so after construction
the class' `type' field has the same value as the `type' parameter,
and the `children' field refers to the same array as the `children'
parameter.
If you're still confused, please describe in more detail just
what you're confused about.
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [next] | [standalone]
| From | Popping mad <rainbow@colition.gov> |
|---|---|
| Date | 2016-02-15 13:09 +0000 |
| Message-ID | <n9sime$jvh$1@reader1.panix.com> |
| In reply to | #33804 |
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[] ??
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2016-02-15 05:14 -0800 |
| Message-ID | <9ff8ca1c-63e9-4d6e-a006-946dd47e1469@googlegroups.com> |
| In reply to | #33806 |
On Monday, February 15, 2016 at 8:09:45 AM UTC-5, 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[] ?? correct children is just a variable. Node is declaring what kind of variable. If you want to make an array, put the [] on the Node part.
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2016-02-15 08:43 -0500 |
| Message-ID | <n9skg2$ggb$1@dont-email.me> |
| In reply to | #33806 |
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
[toc] | [prev] | [next] | [standalone]
| From | Andreas Leitgeb <avl@logic.at> |
|---|---|
| Date | 2016-02-15 13:46 +0000 |
| Message-ID | <slrnnc3lrg.456.avl@login.logic.tuwien.ac.at> |
| In reply to | #33806 |
Popping mad <rainbow@colition.gov> wrote:
> On Mon, 15 Feb 2016 07:52:56 -0500, Eric Sosman wrote:
>> ...
within: public Node(Type type, Node... children) {
> is specifically what has me confused. Thanks.
The three dots are called an "ellipsis".
With this information you can now easily google for
Java ellipsis
and find more information about it, than anyone would
bother typing or copy&pasting into a response here.
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2016-02-15 06:03 -0800 |
| Message-ID | <dbd3c730-7b6e-4902-8f0a-6de68c1e068f@googlegroups.com> |
| In reply to | #33810 |
On Monday, February 15, 2016 at 8:49:44 AM UTC-5, Andreas Leitgeb wrote: > The three dots are called an "ellipsis". > > With this information you can now easily google for > > Java ellipsis > > and find more information about it, than anyone would > bother typing or copy&pasting into a response here. It groups an infinite number of arguments into a single collection, so of course may only be used on the last parameter, most common example java.util.Arrays.asList()
[toc] | [prev] | [next] | [standalone]
| From | j4n bur53 <janburse@fastmail.fm> |
|---|---|
| Date | 2016-02-15 15:54 +0100 |
| Message-ID | <n9sorl$724$1@news.albasani.net> |
| In reply to | #33811 |
Eric Douglas schrieb: >> >and find more information about it, than anyone would >> >bother typing or copy&pasting into a response here. > It groups an infinite number of arguments into a single > collection, so of course may only be used on the last parameter, > most common example java.util.Arrays.asList() I want to see the programming language that can group an *infinite* number of arguments, except maybe functional programming languages such as Haskell that have lazy lists. I guess you mean an arbirary number, i.e. any number of arguments that are representable as an array in Java, which is usually MAX_INTEGER - array_overhead. Plus the restrictions that the heap gives. Bye
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2016-02-15 07:24 -0800 |
| Message-ID | <9fb2e9af-f704-4e51-9904-bb5b9283032f@googlegroups.com> |
| In reply to | #33813 |
On Monday, February 15, 2016 at 9:54:59 AM UTC-5, j4n bur53 wrote: > I want to see the programming language that can group an > *infinite* number of arguments, except maybe functional > programming languages such as Haskell that have lazy lists. > > I guess you mean an arbirary number, i.e. any number of > arguments that are representable as an array in Java, > which is usually MAX_INTEGER - array_overhead. Plus the > restrictions that the heap gives. > > Bye No doubt there may be a limit, likely the MAX_INTEGER, but I'd hate to see valid code that hits that limit.
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2016-02-15 11:08 -0500 |
| Message-ID | <n9st0k$itv$1@dont-email.me> |
| In reply to | #33814 |
On 2/15/2016 10:24 AM, Eric Douglas wrote:
> On Monday, February 15, 2016 at 9:54:59 AM UTC-5, j4n bur53 wrote:
>> I want to see the programming language that can group an
>> *infinite* number of arguments, except maybe functional
>> programming languages such as Haskell that have lazy lists.
>>
>> I guess you mean an arbirary number, i.e. any number of
>> arguments that are representable as an array in Java,
>> which is usually MAX_INTEGER - array_overhead. Plus the
>> restrictions that the heap gives.
>>
>> Bye
>
> No doubt there may be a limit, likely the MAX_INTEGER, but I'd hate to see valid code that hits that limit.
A single method or constructor can have only 65535 (6?) bytes
of byte code, and filling in each slot of the array takes at least
four byte code instructions: Push (or dup) the array reference,
push the index, push the value, store-to-array-slot. So, no: You'll
never see a method call with anything like Integer.MAX_VALUE
arguments.
Thank goodness!
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2016-02-15 11:17 -0500 |
| Message-ID | <n9stnk$hs7$1@gioia.aioe.org> |
| In reply to | #33816 |
On 2/15/2016 11:08 AM, Eric Sosman wrote: > On 2/15/2016 10:24 AM, Eric Douglas wrote: >> On Monday, February 15, 2016 at 9:54:59 AM UTC-5, j4n bur53 wrote: >>> I want to see the programming language that can group an >>> *infinite* number of arguments, except maybe functional >>> programming languages such as Haskell that have lazy lists. >>> >>> I guess you mean an arbirary number, i.e. any number of >>> arguments that are representable as an array in Java, >>> which is usually MAX_INTEGER - array_overhead. Plus the >>> restrictions that the heap gives. >>> >>> Bye >> >> No doubt there may be a limit, likely the MAX_INTEGER, but I'd hate to >> see valid code that hits that limit. > > A single method or constructor can have only 65535 (6?) bytes > of byte code, and filling in each slot of the array takes at least > four byte code instructions: Push (or dup) the array reference, > push the index, push the value, store-to-array-slot. So, no: You'll > never see a method call with anything like Integer.MAX_VALUE > arguments. > > Thank goodness! 16K arguments is still absolutely unreadable. :-) Arne
[toc] | [prev] | [next] | [standalone]
| From | Andreas Leitgeb <avl@logic.at> |
|---|---|
| Date | 2016-02-15 16:34 +0000 |
| Message-ID | <slrnnc3vmb.456.avl@login.logic.tuwien.ac.at> |
| In reply to | #33818 |
Arne Vajhøj <arne@vajhoej.dk> wrote: > On 2/15/2016 11:08 AM, Eric Sosman wrote: >> On 2/15/2016 10:24 AM, Eric Douglas wrote: >>> On Monday, February 15, 2016 at 9:54:59 AM UTC-5, j4n bur53 wrote: >>>> I want to see the programming language that can group an >>>> *infinite* number of arguments, ... >>> No doubt there may be a limit, likely the MAX_INTEGER, but I'd hate to >>> see valid code that hits that limit. >> A single method or constructor can have only 65535 (6?) bytes >> of byte code, and filling in each slot of the array takes at least >> four byte code instructions [...] So, no: You'll never see a method >> call with anything like Integer.MAX_VALUE arguments. > 16K arguments is still absolutely unreadable. That all said and true, I now feel like pointing out what is known to the experts, but perhaps not quite so for newcomers: The Node constructor in the first Post might still see MAX_VALUE elements within children, because the constructor can also be called with a single array (and not only by individual Nodes). Someone could create an array like: Node[] bigNodeArray = new Node[Integer.MAX_VALUE]; then maybe fill it in a loop, and finally create a new Node like: new Node( someType, bigNodeArray );
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2016-02-15 11:43 -0500 |
| Message-ID | <n9sv7u$kh6$2@gioia.aioe.org> |
| In reply to | #33820 |
On 2/15/2016 11:34 AM, Andreas Leitgeb wrote: > Arne Vajhøj <arne@vajhoej.dk> wrote: >> On 2/15/2016 11:08 AM, Eric Sosman wrote: >>> On 2/15/2016 10:24 AM, Eric Douglas wrote: >>>> On Monday, February 15, 2016 at 9:54:59 AM UTC-5, j4n bur53 wrote: >>>>> I want to see the programming language that can group an >>>>> *infinite* number of arguments, ... >>>> No doubt there may be a limit, likely the MAX_INTEGER, but I'd hate to >>>> see valid code that hits that limit. >>> A single method or constructor can have only 65535 (6?) bytes >>> of byte code, and filling in each slot of the array takes at least >>> four byte code instructions [...] So, no: You'll never see a method >>> call with anything like Integer.MAX_VALUE arguments. >> 16K arguments is still absolutely unreadable. > > That all said and true, I now feel like pointing out what is known > to the experts, but perhaps not quite so for newcomers: > > The Node constructor in the first Post might still see MAX_VALUE > elements within children, because the constructor can also be > called with a single array (and not only by individual Nodes). Very relevant point IMHO. Arne
[toc] | [prev] | [next] | [standalone]
| From | Jan Burse <janburse@fastmail.fm> |
|---|---|
| Date | 2016-02-15 20:44 +0100 |
| Message-ID | <n9t9r1$8pf$1@news.albasani.net> |
| In reply to | #33823 |
Arne Vajhøj schrieb:
>> The Node constructor in the first Post might still see MAX_VALUE
>> elements within children, because the constructor can also be
>> called with a single array (and not only by individual Nodes).
>
> Very relevant point IMHO.
Well my point was Java doesn't have *infinite*
arrays. In the same sense as BigInteger doesn't
provide *infinite* integers.
BigInteger only provides elements of Nat, limited
by resources. And even if there were no resource
limites, any element you pick from Nat is still finite.
And since an array is basically a mapping from
a set {0..k-1} to its domain, where you pick k from
Nat, arrays are also pretty finite, provided the domain
elements are each finite.
And if you would allow for arrays that k can have any
value from Nat, if there were no resource limits, still
the array would be finite and not *infinite*.
Bye
[toc] | [prev] | [next] | [standalone]
| From | Jan Burse <janburse@fastmail.fm> |
|---|---|
| Date | 2016-02-15 20:44 +0100 |
| Message-ID | <n9t9ro$8pf$2@news.albasani.net> |
| In reply to | #33826 |
Jan Burse schrieb: > BigInteger only provides elements of Nat, limited Nat --> Z
[toc] | [prev] | [next] | [standalone]
| From | Jan Burse <janburse@fastmail.fm> |
|---|---|
| Date | 2016-02-15 20:45 +0100 |
| Message-ID | <n9t9tj$8pf$3@news.albasani.net> |
| In reply to | #33826 |
Jan Burse schrieb: > And if you would allow for arrays that k can have any > value from Nat, if there were no resource limits, still > the array would be finite and not *infinite*. Since Nat does have an element that is *infinite*.
[toc] | [prev] | [next] | [standalone]
| From | Andreas Leitgeb <avl@logic.at> |
|---|---|
| Date | 2016-02-16 10:05 +0000 |
| Message-ID | <slrnnc5t86.456.avl@login.logic.tuwien.ac.at> |
| In reply to | #33828 |
Jan Burse <janburse@fastmail.fm> wrote: > Jan Burse schrieb: >> And if you would allow for arrays that k can have any >> value from Nat, if there were no resource limits, still >> the array would be finite and not *infinite*. > Since Nat does have an element that is *infinite*. Not sure, what "Nat" you are talking about, but in mathematics, the set of natural numbers, commonly denoted with symbol ℕ, does *NOT* contain a single infinite element. It does of course still contain an infinite number of (each finite!) elements.
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2016-02-15 21:46 -0500 |
| Message-ID | <n9u2j0$blv$2@gioia.aioe.org> |
| In reply to | #33826 |
On 2/15/2016 2:44 PM, Jan Burse wrote: > Arne Vajhøj schrieb: >>> The Node constructor in the first Post might still see MAX_VALUE >>> elements within children, because the constructor can also be >>> called with a single array (and not only by individual Nodes). >> >> Very relevant point IMHO. > > Well my point was Java doesn't have *infinite* > arrays. In the same sense as BigInteger doesn't > provide *infinite* integers. I think we at this point had switched the discussion from infinite to 64K. Arne
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2016-02-15 09:34 -0500 |
| Message-ID | <n9snlj$5o7$1@gioia.aioe.org> |
| In reply to | #33806 |
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[] ?? Both are valid in Java with the same meaning. By convention the first form suggested by Eric is what is used. Arne
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web