Are there any reasons to make all fields and variables final?
- by Roman
In my current project I noticed that all class fields and variable inside methods are declared with final modifier whenever it's possible.
Just like here:
private final XMLStreamWriter _xmlStreamWriter;
private final Marshaller _marshaller;
private final OutputStream _documentStream;
private final OutputStream _stylesStream;
private final XMLStreamWriter _stylesStreamWriter;
private final StyleMerger _styleMerger;
public DocumentWriter(PhysicalPackage physicalPackage) throws IOException {
final Package pkg = new Package(physicalPackage);
final Part wordDocumentPart = pkg.createPart(
"/word/document.xml",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument");
// styles.xml
final Pair<Part, String> wordStylesPart = wordDocumentPart.createRelatedPart(...);
...
}
Are there any reasons to do so?
p.s. As I know project is not supposed to be multithreaded (at least I've heard nothing about it).