You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code, using Guava's TypeToken, returns 'true' in JDK6 and 'false' in JDK7.
TypeToken listOfByteArray = new TypeToken<List<byte[]>>(){};
TypeToken listOfByteArray2 = TypeToken.of(com.google.inject.util.Types.listOf(byte[].class));
System.out.println(listOfByteArray2.isAssignableFrom(listOfByteArray));
This is because listOfByteArray2 is a ParameterizedType whose argument is a GenericArray whose component type is byte[].
This matches the JDK6 behaviour when reflecting on a field of type List<byte[]>.
From sammccall@google.com on July 17, 2012 11:37:29
This code, using Guava's TypeToken, returns 'true' in JDK6 and 'false' in JDK7.
TypeToken listOfByteArray = new TypeToken<List<byte[]>>(){};
TypeToken listOfByteArray2 = TypeToken.of(com.google.inject.util.Types.listOf(byte[].class));
System.out.println(listOfByteArray2.isAssignableFrom(listOfByteArray));
This is because listOfByteArray2 is a ParameterizedType whose argument is a GenericArray whose component type is byte[].
This matches the JDK6 behaviour when reflecting on a field of type List<byte[]>.
In JDK7 a bug was fixed ( http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784); this type is now represented by a ParameterizedType whose argument is byte[].class.
So the correct behaviour, I think, is to detect the current JDK version and use the appropriate implementation.
The corresponding class in Guava does this: https://code.google.com/p/guava-libraries/source/browse/guava/src/com/google/common/reflect/Types.java#471
Original issue: http://code.google.com/p/google-guice/issues/detail?id=715
The text was updated successfully, but these errors were encountered: