0

I find weird that a method has a length

Line 6 and 7. What is method1.length And method10.length I know it returns some number. But what is that number. Please i need help https://code.sololearn.com/c9mRX8q57wi4/?ref=app

28th Aug 2020, 11:23 PM
stephen haokip
stephen haokip - avatar
2 Respuestas
+ 1
A stack trace is an array of StackTraceElement. Why wouldn't it have a length? Outside of Java, all stacks of anything have a height. Consider a stack of books. Height is to stack as length is to array. Maybe you're overlooking that the stack contains something other than its length. Every element in the stack represents a method call. If method1 calls method2... and method10, the stack is an array of all those method calls and the length is how many calls happen. Method 1 returns 12 because the call stack it leads to is [ main, method1, method2, method3, method4, method5, method6, method7, method8, method9, method10, java.lang.Thread.getStackTrace ] and there are 12 elements in that array.
28th Aug 2020, 11:50 PM
Josh Greig
Josh Greig - avatar
0
Josh greig thank you
29th Aug 2020, 9:31 AM
stephen haokip
stephen haokip - avatar