Optional boolean argument for a java method:
void testOptionalArgument(boolean ... flag) {
if (flag == null) {
log.info("optional flag null");
} else {
int length = flag.length;
log.info("optional flag: " + flag + " length: " + length);
if (length > 0) {
log.info("optional flag: " + flag[0]);
}
}
}
Calling this method in 3 different ways:
testOptionalArgument(); // optional flag: [Z@ed3c51 length: 0
testOptionalArgument(true); // optional flag: [Z@1131359 length: 1 optional flag: true
testOptionalArgument(false); // optional flag: [Z@15b3baf length: 1 optional flag: false
Saturday, December 07, 2013
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment