Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #39055

Re: getFibonacciArray() cannot call getFibonacciArray(int from)

From Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: getFibonacciArray() cannot call getFibonacciArray(int from)
Date 2019-08-01 19:15 +0200
Organization A noiseless patient Spider
Message-ID <qhv6p1$p7p$1@dont-email.me> (permalink)
References <87o91amsyc.fsf@munus.decebal.nl>

Show all headers | View raw


On 2019-07-31 11:52, Cecil Westerhof wrote:
> I have the following code I use in jshell:
>     long[] getFibonacciArray() {
>         return getFibonacciArray(0);
>         // return getFibonacciStreamFrom(0).toArray();
>     }
> 
>     long[] getFibonacciArray(int from) {
>         return getFibonacciStreamFrom(from).toArray();
>     }
> 
>     long[] getFibonacciArray(int from, int to) {
>         // check parameters
>         int count = to - from;
>         return getFibonacciStreamFrom(from).limit(count).toArray();
>     }
> 
>     // Needs at least Java 9 because we use a predicate in the iterator
>     // Index 0 of stream i element always contains fibonacci(i) and
>     // index 1 always contains fibonacci(i + 1)
>     // So the map makes sure you have the fibonacci number
>     LongStream getFibonacciStream() {
>         return Stream.
>             iterate(new long[]{0, 1}, t -> t[0] >= 0, t -> new long[]{t[1], t[0] + t[1]})
>             .mapToLong(t -> t[0]);
>     }
> 
>     LongStream getFibonacciStreamFrom(int from) {
>         // Check parameter
>         return getFibonacciStream().skip(from).map(l -> l);
>     }
> 
> When I call this with:
>     jshell --startup DEFAULT ~/Java/Jshell/test.jsh
> 
> I get:
>     |  Error:
>     |  method getFibonacciArray in class  cannot be applied to given types;
>     |    required: no arguments
>     |    found: int
>     |    reason: actual and formal argument lists differ in length
>     |      return getFibonacciArray(0);
<snip />
> 
> What is happening here?
> 

If I had to hazard a guess, I would say that in jshell, you can't
reference a method before you've declared it (lexically speaking).

-- 
DF.

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

getFibonacciArray() cannot call getFibonacciArray(int from) Cecil Westerhof <Cecil@decebal.nl> - 2019-07-31 11:52 +0200
  Re: getFibonacciArray() cannot call getFibonacciArray(int from) Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2019-08-01 19:15 +0200
    Re: getFibonacciArray() cannot call getFibonacciArray(int from) Andreas Leitgeb <avl@logic.at> - 2019-08-02 06:51 +0000
    Re: getFibonacciArray() cannot call getFibonacciArray(int from) Cecil Westerhof <Cecil@decebal.nl> - 2019-08-03 11:26 +0200
  Re: getFibonacciArray() cannot call getFibonacciArray(int from) Cecil Westerhof <Cecil@decebal.nl> - 2019-08-03 11:11 +0200

csiph-web