I have witten a line of code and the length is 126 character so i want to know if I am permitted to do something like this
if (attribute.getAttributeType().getMaxOccurs() != null &&
attribute.getAttributeType().getMaxOccurs() != 1) {
}
I have witten a line of code and the length is 126 character so i want to know if I am permitted to do something like this
if (attribute.getAttributeType().getMaxOccurs() != null &&
attribute.getAttributeType().getMaxOccurs() != 1) {
}
if (attribute.getAttributeType().getMaxOccurs() != null
&& attribute.getAttributeType().getMaxOccurs() != 1) {
}
This is my personal preference. 80 characters isn’t always hard and fast…
Alternative:
if (attribute.getAttributeType().
getMaxOccurs() != null &&
attribute.getAttributeType().
getMaxOccurs() != 1) {
}
Thank you for your feedback
These aren’t hard and fast rules either.
I quickly jumped to https://wiki.openmrs.org/display/docs/Java+Conventions hoping to find a recommendation for that but did not.
I would also go for @r0bby’s preference.
As you have chained 2 method calls, what I would do is, take it to a local variable and use it. It increases the readability while reducing the line length.
Integer attrMaxOccrs = attribute.getAttributeType().getMaxOccurs();
if (attrMaxOccrs != null && attrMaxOccrs != 1) {
}
That works, I’d still put the conditionals on separate lines.
thanks for the tip