Fostah
Fostah

Reputation: 11776

Performance side effect with static internal Util classes?

For a util class that contains a bunch of static functionality that's related to the same component, but has different purposes, I like to use static internal classes to organize the functionality, like so:

class ComponentUtil {
    static class Layout {                    
        static int calculateX(/* ... */) {
            // ...
        }

        static int calculateY(/* ... */) {
            // ...
        }
    }

    static class Process {
        static int doThis(/* ... */) {
            // ...
        }

        static int doThat(/* ... */) {
            // ...
        }
    }
}

Is there any performance degradation using these internal classes vs. just having all the functionality in the Util class?

Upvotes: 1

Views: 158

Answers (1)

Riduidel
Riduidel

Reputation: 22292

No : at compile time, a static internal class will be compiled as an external class file, having as name (in your example) ComponentUtil$Layout. Hopefully, references to this class will be resolved in the whole project. But it will be considered, at run time, like a totally independant class.

Upvotes: 4

Related Questions