4 ms·
> And no, nested classes are not the same thing. They actually are if they're public static. Quite literally so, nested static classes are the exact same as "n
by beeboobaa 3y ago
> And no, nested classes are not the same thing.
They actually are if they're public static. Quite literally so, nested static classes are the exact same as "normal" classes but named `OuterName$InnerName.class`
- occz 3y agoIt might be for the compiler, but the nesting implies hierarchy for the reader, which may or may not be desirable.
- beeboobaa 3y agoSame goes for putting them in the same file.
- dtech 3y agoThey are not the same at all. One practical reason is that in Kotlin (and other languages supporting this) you can always move the class to a dedicated file if it or the file becomes to unwieldy. With a nested class all the imports would need to change, which is a no go unless you can refactor all code using it in 1 go.
- beeboobaa 3y agoThis only matters if you are building a library intended to be consumed by other projects, and you are intending to release before deciding on a public API, and for some reason put multiple classes in a single file. Pretty specific case of a bad practice. Otherwise, just use your IDE's refactor capabilities.