Cannot instantiate the type Pair although not abstract

Clash Royale CLAN TAG#URR8PPPCannot instantiate the type Pair although not abstract
Trying to write an iterator that returns a Pair:
Part of my PairIterator
public Pair next() {
this.counter ++;
Pair p = new Pair(this.l.get(counter - 1), this.l.get(counter));
//error occurs here
}
public class Pair<E> {
private E e1;
private E e2;
public Pair(E e1, E e2) {
this.e1 = e1;
this.e2 = e2;
}
public E first() {
return this.e1;
}
public E second() {
return this.e2;
}
}
getting
Cannot instantiate the type Pair
... although Pair is not an abstract class/interface. Why is this happening?
I see no examples of 'new Pair' here, so we cannot guess what you did.
– bmargulies
Aug 20 '17 at 16:10
counter is probably a long or an ind, but what type is this.l?
– Heri
Aug 20 '17 at 16:22
Welcome to Stack Overflow! Please take the tour, have a look around, and read through the help center , in particular How do I ask a good question? and What topics can I ask about here?. Please provide a Minimal, Complete, and Verifiable example (MCVE)
– Timothy Truckle
Aug 20 '17 at 16:23
@bmargulies "new Pair" appears in the 3rd line of the snippet.
– dunni
Aug 20 '17 at 16:29
2 Answers
2
Make sure to import the correct class to initialize your pair object.
import org.apache.commons.math3.util.Pair;
Concrete Class -> Can directly create object.
This gives an error:
import org.apache.commons.lang3.tuple.Pair;
Its an abstract class, so you can't create the object directly.
Most likely because you didn't add generic type parameters to Pair.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What is this.counter? No mention any where!
– nagendra547
Aug 20 '17 at 16:08