Stefan Ram schrieb:
Christian <fakemail@xyz.de> writes:
Often in my code I find situation when it would have been
helpful/produced nicer code if I were able to change a final
variable while being in the constructor .
If this happens so often, then it
should be easy to post an example.
here an example for my last recent occurence..
/**
* decorates a normal NC Block that is a TreeCoding Block
*/
public TreeCodingBlock(INCBlock block, TreeCodingBlockmanager manager) {
this.decorated = block;
this.manager = manager;
int firstPositionUnequalZero = 0;
int lastPositionUnequalZero = 0 ;
ByteVector linearfactors = block.getLinearFactors();
for (int i=0; i < linearfactors.length(); i++) {
if (linearfactors.getElement(i) != 0) {
firstPositionUnequalZero = i;
break;
}
}
for (int i = linearfactors.length()-1 ; i >= 0 ; i-- ) {
if (linearfactors.getElement(i) != 0) {
lastPositionUnequalZero = i;
break;
}
}
this.firstPositionUnequalZero = firstPositionUnequalZero;
this.lastPositionUnequalZero = lastPositionUnequalZero;
}
Well I can remember worse examples.. here it adds just four lines of
code. Though four lines that seem unecessary.
ByteVector if possible.