java - Arbitrary Number of Arrays (Oracle tutorial) -


so learned varargs on java oracle tutorial, , having trouble reading code. example, "(point... corners)" know shorten version of (point[] corners) "point"? array tells (x,y) coordinate(s) define? also, not understand what"(corners[1].x)" means. dot notation ".x , .y", , happening other "corners"? sorry questions, know may seem stupid questions, i, nevertheless, thank time.

public polygon polygonfrom(point... corners) { int numberofsides = corners.length; double squareofside1, lengthofside1;  // "corners" array dot notations below confuse me most.  // there values stored in each index correct? //so "corner[1].x contain element 6 right?  squareofside1 = (corners[1].x - corners[0].x)                  * (corners[1].x - corners[0].x)                   + (corners[1].y - corners[0].y)                  * (corners[1].y - corners[0].y); lengthofside1 = math.sqrt(squareofside1);  // more method body code follows creates , returns  // polygon connecting points 

}

from tutorial:

assume point class represents x, y coordinate

so, point hypothetical class looks this:

class point {     int x;     int y; } 

the polygon class constructed arbitrary array of points. syntax corners[1].x returns value of x field on second point object in corners array.


Comments