In my own vector class there is a method of construction:
Public vector (float[] vector) {this.vector = Vector;this.length = Vector.length;this.size = Vectorutil.computevectorsize (vector);}
This construction method calls Vectorutil's Computevectorsize (float[] vector) method to calculate the length of the vector, and the computevectorsize (float[] vector) method is as follows:
public static float computevectorsize (float[] vector) {vector vector2 = new vector (vector); return computevectorsize ( VECTOR2);}
because we have previously written a method for calculating the length of vectors by passing in vector objects, we have constructed a vector object directly from the array, and then passed it to another method to calculate the length of the vector. Everything seems reasonable, but this leads to cyclic invocation: vector (float[] vector) method call Computevectorsize (float[] vector) method, Computevectorsize (float[] Vector) method call vector (float[] vector) method, vector (float[] vector) and call computevectorsize (float[] vector) .... It then causes the java.lang.StackOverflowError exception.
So, usually write code, pay attention to the method of cyclic call.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java two methods call each other to cause a java.lang.StackOverflowError