ballerina-lang
ballerina-lang copied to clipboard
[Refactoring] Make inner classes static
Purpose
A non-static inner class has a reference to its outer class, and access to the outer class' fields and methods. That class reference makes the inner class larger and could cause the outer class instance to live in memory longer than necessary.
If the reference to the outer class isn’t used, it is more efficient to make the inner class static (also called nested). If the reference is used only in the class constructor, then explicitly pass a class reference to the constructor. If the inner class is anonymous, it will also be necessary to name it.
However, while a nested/static class would be more efficient, it’s worth noting that there are semantic differences between an inner class and a nested one:
- an inner class can only be instantiated within the context of an instance of the outer class.
- a nested (static) class can be instantiated independently of the outer class.
https://sonarcloud.io/organizations/ballerina-platform/rules?open=java%3AS2694&q=inner+class&tab=why
Check List
- [x] Read the Contributing Guide
- [ ] Updated Change Log
- [ ] Checked Tooling Support (#<Issue Number>)
- [ ] Added necessary tests
- [ ] Unit Tests
- [ ] Spec Conformance Tests
- [ ] Integration Tests
- [ ] Ballerina By Example Tests
- [ ] Increased Test Coverage
- [ ] Added necessary documentation
- [ ] API documentation
- [ ] Module documentation in Module.md files
- [ ] Ballerina By Examples
Codecov Report
Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
Project coverage is 77.30%. Comparing base (
4e71d28) to head (2f331d4). Report is 396 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@
## master #42915 +/- ##
============================================
- Coverage 77.34% 77.30% -0.04%
- Complexity 58244 58532 +288
============================================
Files 3450 3460 +10
Lines 218950 220074 +1124
Branches 28736 28911 +175
============================================
+ Hits 169337 170125 +788
- Misses 40288 40544 +256
- Partials 9325 9405 +80
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.
Remove state status
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.