java - Can I check if a void method returned? -
i want ask, if possible check if void method "cancelled" calling return;?
for illustration in main phone call calculate(myarray);, defined follows:
public static void calculate(object[] array) { if (array == null) return; // stuff } is way know, if returned or not? thoughts making "global" boolean changed true right before homecoming , check value in main or alter homecoming type int , when returned @ origin utilize return -1; , @ end of method return 0;
both possible think neither of them style. there alternative?
no, cannot. the oracle java tutorials - returning value method:
any method declared void doesn't homecoming value. not need contain return statement, may so. in such case, return statement can used branch out of command flow block , exit method , used this:
return; there no way method invocation determine if void method completed fall-through block or return; statement.
most other methods includes homecoming type of boolean , returns false when went wrong, or throws illegalargumentexception.
java arrays method-invocation return
No comments:
Post a Comment