| Author |
maximum number of statements in a method
|
John Mallavalli
Ranch Hand
Joined: Apr 24, 2002
Posts: 46
|
|
Hi, Is there a limit for the number of statements in a java method or is it possible to have any number of statements in a java method ? Thanks in advance. John
|
Do not let what you cannot do interfere with what you can do !!<br /> <br />SCJP & SCWCD 1.4
|
 |
Ben Wood
Ranch Hand
Joined: Aug 14, 2001
Posts: 342
|
|
|
Technically I'm not aware of there being a restriction, but I would be wary of writing bloated methods performing more than one task and running into several hundered lines. Always best practice to split something up into several smaller methods to avoid confusing code. Also makes it easier to track bugs IMO.
|
SCJP 1.4, www.gsi3d.org.uk
|
 |
John Mallavalli
Ranch Hand
Joined: Apr 24, 2002
Posts: 46
|
|
Yes..I understand that its a bad practice to have bloated methods. I just wanted to know if at all there is any restriction on the limit for the number of statements in a java method. Anyway thanks for your response. - John
|
 |
Vlado Zajac
Ranch Hand
Joined: Aug 03, 2004
Posts: 244
|
|
I don't know if such limit exists but there's a maximum size of bytecode compiled method. It's 64KB. [ August 26, 2004: Message edited by: Vlado Zajac ]
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12269
|
|
As I recall, there is a limit on the size of a compiled method based on the number of byte codes - not the number of lines. I think the limit is due to the fact that jumps are coded in 16 bits so your compiled method must be less than 32K in size. This limitation should be familiar to anybody who has coded in assembly language. Bill
|
 |
John Mallavalli
Ranch Hand
Joined: Apr 24, 2002
Posts: 46
|
|
|
Thanks guys.
|
 |
 |
|
|
subject: maximum number of statements in a method
|
|
|