How to avoid @SuppressWarnings with anonymous inner classes in Java?
<p>I'm struggling with smarter coding style in usage of anonymous classes.</p>

<p>How can I use anonymous inner class WITHOUT
    @SuppressWarnings 
in the case below?</p>

<p>When using anonymous classes like this way:</p>

<pre><code>someMethod( new Y(){

    // non-overriding public method
    public void echo1(){
        // do some stuff
    }

} );

...

public abstract class Y
{
    // use me as an anonymous class,
    // and define any methods when defining me
}
</code></pre>

<p>This code makes warning.</p>

<p>public method "echo1" needs to be annotated 
    @SuppressWarnings("unused")
.</p>

<p>If I code additionally echo2, echo3, echo4,... all methods needs to be annotated one by one.</p>

<p>In order to avoid writing annotations frequently,
I tried to code this way for propagating annotation effects over all child classes:</p>

<pre><code>@Inherited // &lt;- This is what I want this annotation to be!
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface SuppressWarningsPropagate extends SuppressWarnings
{
}
</code></pre>

<p>then I tried to annotate class Y with this annotation.
This would be useful and simple enough to annotate only one base class.</p>

<p>...and I found myself stupid. </p>

<p>Annotations like 
    SuppressWarnings 
can't be "extended" nor "implemented".</p>

<p>Instead, this code works and has no warnings, because SuppressWarnings goes well for this only one concrete class:</p>

<pre><code>@SuppressWarnings("unused")
public class X
{
    private int i;
    private int j;
}
</code></pre>

<p>In summary, how can I...</p>

<ul>
<li>use anonymous inner class (for good readability of code)</li>
<li>and also defining public methods on 
new
(must be public, for the matter of addJavascriptInterface() of Android SDK)</li>
<li>and also avoid writing @SuppressWarnings("unused") for all the methods one by one (for good writability)</li>
</ul>

<p>...possible? or am I just daydreaming?</p>

<p>Thanks a lot in advance.</p>
