class of a generic collection at runtime with serialVersionUID?

Is this the only way to get the class of a generic collection at runtime?

Class<T> clazz = new HashSet<Task>() {
            private static final long serialVersionUID = 8252429191034335636L;
        }.getClass()

My IDE says:

“The serializable class does not declare a static final serialVersionUID field of type long”

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

Nothing to do with serialization, but:

private static Set<Task> myField;

...

        Field field = MyClass.class.getDeclaredField("myField");
        Type type = field.getGenericType();
        ParameterizedType ptype = (ParameterizedType)type;
        Type[] argTypes = ptype.getActualTypeArguments();
        Type atype = argTypes[0];
        System.out.println(atype.getTypeName());