I'm losing the type of a variable in a generic method when passing to a second generic method with varargs
===

I guess it's probably best to start with the behaviour I'm looking at:

    public class genericTest {
    	public static void main(String[] args) {
    		String str = "5318008";

    		printClass(str);    	      // class java.lang.String
    		callPrintClass(str);          // class java.lang.String

    		printClassVarargs(str);       // class java.lang.String
    		callPrintClassVarargs(str);   // class java.lang.Object
    	}
    	
    	public static <T> void printClass(T str) {
    		System.out.println(str.getClass());
    	}

    	public static <T> void printClassVarargs(T ... str) {
    		System.out.println(str.getClass().getComponentType());
    	}
    	
    	public static <T> void callPrintClass(T str) {
    		printClass(str);
    	}

    	@SuppressWarnings("unchecked")
    	public static <T> void callPrintClassVarargs(T str) {
    		printClassVarargs(str);
    	}
    }

Looking at <code>printClass()</code> and <code>callPrintClass()</code>, it seems like everything is working fine. <code>callPrintClass()</code> takes a generic argument and passes it along. <code>printClass()</code> recognises this variable by its correct type, not caring who is sending the parameter, and then does as it's supposed to and prints <code>java.lang.String</code>. 

But when we try to use varargs, this stops working. I would expect <code>printClassVarargs()</code> to recognise it's argument is of type <code>String[]</code>, much like the method without varargs recognises the type of its argument. Notice also that this doesn't happen if I call <code>printClassVarargs()</code> directly (it's perfectly happy there to output <code>String</code>), but only when it's called by <code>callPrintClassVarargs()</code>, where it forgets the type of its argument and presumes it's getting an <code>Object</code>. I also realise I'm having to suppress a compiler warning here, which usually comes along when I'm trying to cast generics, but I'm not sure what exactly is going on there. 

So my question is really two. What is the reason behind this behaviour? Is this some consequence of type erasure, or the way Java handles arrays? And secondly, is there any way around this? 

This is only a simple example, of course. I'm not trying to print class names this way, but originally found the problem while writing an overloaded method to concatenate arrays. 