I have the following class that has the capability of performing a deep copy of itself.
public class XPolygon {
private XVector[] points;
XPolygon(XVector... points)
{
this.points = points;
}
public XPolygon copy()
{
return new XPolygon((XVector[])Arrays.stream(this.points).map(XVector::copy).toArray());
}
}
Please consider this to be an academic exercise. When the copy
method of an instance is called, the following exception is generated:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [LXVector;
at XPolygon.copy(XPolygon.java:17)
What is the proper way of calling the XPolygon
constructor to prevent an error for occurring?