Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <a href="http://checkstyle.sourceforge.net/config_coding.html#RequireThis" rel="nofollow noreferrer">RequireThis</a> rule does have a valid use in that it can prevent a possible bug in methods and constructors when it applies to fields. The code below is almost certainly a bug:</p> <pre><code>void setSomething(String something) { something = something; } </code></pre> <p>Code like this will compile but will do nothing except reassign the value of the method parameter to itself. It is more likely that the author intended to do this:</p> <pre><code>void setSomething(String something) { this.something = something; } </code></pre> <p>This is a typo that could happen and is worth checking for as it may help to prevent hard to debug problems if the code fails because <code>this.something</code> is not set much later in the program.</p> <p>The checkstyle settings allow you to keep this useful check for fields while omitting the largely unnecessary check for methods by configuring the rule like this:</p> <pre><code> &lt;module name="RequireThis"&gt; &lt;property name="checkMethods" value="false"/&gt; &lt;/module&gt; </code></pre> <p>When it comes to methods this rule has no real effect because calling <code>this.getMeSomething()</code> or just <code>getMeSomething()</code> has no effect on Java's method resolution. Calling <code>this.getSomethingStatic()</code> still works when the method is static this is not an error, it is only a warning in various IDEs and static analysis tools.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload