Skip to content

Can we remove unnecessary 'final's? #2249

@devycarol

Description

@devycarol

I'm not sure how you feel about project-wide style revisions, but could we remove all uses of the 'final' keyword in local contexts in the Java code? That's method parameters and local variables.

We obviously wouldn't do this for fields, methods, or classes, as defaulting those final really is best practice for safety (a point I really agree with Kotlin on).

I can do this with inspection profiles, it would just modify a lot of files.

There's no performance gain that I'm aware of. The JVM can discern "effectively final" variables, which is most of them. If we're concerned about safety, modern code vision tools are a much more effective to that end. I personally color my mutated local variables yellow in my IDE, since mutation should always be done with care.

I don't think it's our job to remedy the design mistake Java made in 1939 or whatever having variables mutable by default by making our code 35% wider. We can save the bytes, the screen space, and the readability. This would allow more space for things that are actually helpful, like nullity annotations and code that actually does stuff. We wouldn't have to type unnecessary letters just to stay consistent with surrounding style.

(And yes, I'm aware most such declarations come from the AOSP era.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions