8

Why does PMD suggest making fields final?

view full story
linux-howto

http://stackoverflow.com – I created Android application and run static analysis tool PMD on it. And what I don't get is why it is giving me warning and says to declare fields final when possible like in this example. final City selectedItem = (City) arg0.getItemAtPosition(arg2); new RequestSender(aaa).execute(xxx, selectedItem.getId()); It just starts inner AsyncTask instance. Is it good style to declare it final and why? For the sake of readability, I created a new object, but PMD says it should be final. (HowTos)