Class is a raw type. References to generic type Class should be parameterized

前端 未结 2 932
不思量自难忘°
不思量自难忘° 2020-11-28 11:52

I have the following class (from a simple Spring tutorial)

public class CarValidator implements Validator {

    public boolean supports(Class aClass) {
             


        
相关标签:
2条回答
  • 2020-11-28 12:04

    The interface declares the method with a raw type. In that case, you can't override it nicely without having the warning.

    The origin of your problem is that the Spring interface was declared to be Java 1.4 compliant. Note that Spring 3.0 is supposed to deliver all classes as Java 1.5 compliant, so that would fix your problem. Before you upgrade, I guess you would have to live with either the warning or the @SuppressWarning.

    0 讨论(0)
  • 2020-11-28 12:28

    Since the interface forces you to use the raw type (i.e. doesn't allow you to specify the correct type information) you can't implement it without warnings unless you use @SupressWarnings.

    The only real fix is to fix the interface (i.e. make it define boolean supports(Class<?> aClass)).

    0 讨论(0)
提交回复
热议问题