Inside of class ATester
{
private A<Integer> p1,p2;
p1 = new B<Integer>();
p2 = new B<Integer>( p1);
}
public class B<E extends Comparable<? super E>> implements A<E>
{
public B() // default constructor
{
// skip
}
public B(B other) // copy constructor
{
// skip
}
}
I want to define a copy constructor, which takes another B as argument
but when I pass p1 into
p2 = new B<Integer>( p1);
when compile, it gives me error message
“no suitable constructor found for B< A < Integer > >”
What should I change or add?
Change it to
Or call as
p2 = new B<Integer>( (B<Integer>)p1);Because what you are trying to do is send
A<Integer>toBin the constructor.Ultimately it is
Which is wrong due to contra-variance of argument type. Either change the argument type in you
Bconstructor as per design or do the above mentioned