Detect classes that do not use inheritance or inner classes that should be `static`
Luro02 opened this issue · 0 comments
Luro02 commented
What it does
One can nest a class in another class like this:
class A {
class B {
}
}
If the class is not static
, it will extend the outer class, making the non-static fields and methods accessible.
In most submissions this behaviour is not intentional and therefore it makes sense to detect these cases.
Problems with this check:
- Time spent implementing this, might not be worth the effort
- Might be difficult to detect if a class uses its inheritance
After implementing this, it should be easy to find classes that inherit from another class, but do not need to inherit from it. Note: I do not think that this happens very often, that is why this issue is marked as low-priority
Things to be careful about with the inheritance thing:
- It should look if the class accesses any constructors/methods/fields of the parent
- How the context looks:
Parent parent = new Child()
Lint Name
INNER_CLASS_SHOULD_BE_STATIC,CLASS_SHOULD_NOT_INHERIT
Category
oop
Example
<code>
Could be written as:
<code>