What does the code for this task have to be like (computer science/intellij IDEA)?

Hello, I'm unfortunately stuck with this task and don't know what my code should look like. I would really appreciate some help 🙂

1 vote, average: 1.00 out of 1 (1 rating, 1 votes, rated)
You need to be a registered member to rate this.
Loading...
Subscribe
Notify of
1 Answer
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
daCypher
2 years ago

This is, as always, a bit difficult if we don't know the classes and packages to which it all refers.

As I understand it, the ArraySequence class should look something like this:

 import java.util.Iterator; public class ArraySequence<T> implements Sequence<T> { private T[] values; public ArraySequence(T[] values) { this.values = values; } public Iterator<T> iterator() { return new Iterator<T>() { int index = 0; @Override public boolean hasNext() { return index < values.length; } @Override public T next() { return values[index++]; } }; } }

and in the interface Sequence the signature for of(T…) should be commented out, like this:

 import java.util.Iterator; interface Sequence<T> extends Iterable<T>{ public Iterator<T> iterator(); // public Sequence<T> of(T... values); }