Java two methods call each other to cause a java.lang.StackOverflowError

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.