How to work around "non-static class T cannot be referenced from a static context"?
<p>How to write a Java function which simply takes an argument of any type, prints it and returns it?</p>

<p>In Scheme I am used to write the following macro:</p>

<pre><code>(define-syntax dump
  (syntax-rules ()
    ((_ arg) (let ((value arg))
               (display 'arg)
               (display " -&gt; ")
               (display value)
               (newline)
               arg))))
</code></pre>

<p>Calling it <code>(+ 1 (dump (* 2 3)))</code> would return 7 and print <code>(* 2 3) -&gt; 6</code>.</p>

<p>I tried something similar in Java:</p>

<pre><code>public class Debug&lt;T&gt;
{
    public static T dump (T arg)
    {
        System.err.println (arg);
        return arg;
    }
}
</code></pre>

<p>But I get the error:</p>

<pre><code>non-static class T cannot be referenced from a static context
</code></pre>

<p>How to solve this?</p>

<p><strong>Edit</strong>
Thanks I got it:</p>

<pre><code>import java.util.Arrays;

public class Debug
{
    public static &lt;T&gt; T dump (T arg)
    {
        System.err.println(arg instanceof Object[] ? 
                           Arrays.toString((Object[])arg) : arg);
        return arg;
    }
}
</code></pre>

<p>Lovely Scheme I grieve for you...</p>
