How to append to a PVector[]

  PVector[] returnv = new PVector[1];

  for(int i = 1; i < line.length - 1; i++) {
    if(140 > getAngle(line[i-1], line[i], line[i+1]) && getAngle(line[i-1], line[i], line[i+1]) > 40) { //If angle is between 40 and 140 degrees it gets added to the returnv array.
      returnv = append(returnv, line[i]); // LINE 36

returnv and line are PVector arrays, I want to add a PVector from line to returnv if it meets certain requirements. However, line 36 (marked in notes) comes out with the error 'Type mismatch, "java.lang.Object" does not match with "processing.core.PVector[]'.



  • edited September 2018 Answer ✓

    If an array changes its length after creation, a List is highly recommended instead: :-bd

    But if you insist on an array container even when changing its length, you're gonna need to use the (cast) operator of the actual datatype for the cases append() returns an Object. :ar!

    returnv = (PVector) append(returnv, line[i]);

Sign In or Register to comment.