Why java Class<?> is generic but Field is not?

Viewed 60

Why java Class<?> is generic but Field is not?

And class in java.beans are not generic such as: BeanInfo, PropertyDescriptor...

When to use generic class? And I want to design a class to represent java bean / pojo (similar as BeanInfo), should I use generic?

1 Answers

Generic types in Java are classes or interfaces and not fields or methods. I think that is why a Class is generic and a Field is not.

My suggestion is for you to write the interface for your class and if you see that you need to pass Object around and do casting, then the generic types should be used.

Related