Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Some are applicable for different technologies.
| EC78 | Const parameter in batch update | Don't set const parameter in batch update => Put its in query. Creating this parameter and destroying it consumes CPU cycles and RAM unnecessarily. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 |
| EC79 | Free resources | try-with-resources Statement needs to be implemented for any object that implements the AutoCloseable interface, it save computer resources. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 |
| EC81 | Specify struct layouts | When possible, specify struct layouts to optimize their memory footprint | | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | ✅ | 🚫 |
| EC82 | Make variable constant | A variable is never reassigned and can be made constant | | 🚀 | 🚀 | 🚀 | 🚀 | 🚀 | ✅ | 🚫 |
| EC82 | Make variable constant | A variable is never reassigned and can be made constant | | | 🚀 | 🚀 | 🚀 | 🚀 | ✅ | 🚫 |
| EC83 | Replace Enum ToString() with nameof | When no string format is applied, use nameof instead of ToString() for performance | | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | ✅ | 🚫 |
| EC84 | Avoid async void methods | Use async Task methods instead, for performance, stability and testability | | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | ✅ | 🚫 |
| EC85 | Make type sealed | Seal types that don't need inheritance for performance reasons | | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | ✅ | 🚫 |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
:!sectids:

Variable can be made constant.

## Why is this an issue ?

Unlike variables, constant values are known at compile time and are injected as is in the code, requiring no runtime processing and therefore reducing the environmental footprint.
Although good compilers will const eligible variables by themselves, it is still good practice to declare them constant, as it makes the code intent clearer.

### When can it be ignored ?

This rule should not be ignored.

## Non-compliant examples

```java
public void Ec82NonCompliant() {
String test = "test"; // Non compliant, i is never reassigned and can be made constant
System.out.println(test);
}
```
## Compliant examples

```java
final String test = "test";

public void Ec82Compliant()
{
System.out.println(test);
}
```