Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java wildcard type safety warning

Tags:

java

generics

Well, I have an interface which is;

public interface abc {
    public<T extends JPanel> T initalize();
}

And I'm implementing it. Here is thing, when I defining function like:

public class Startup_thePanel extends JPanel implements abc {
   public Startup_thePanel initalize() {

            return this;
    }
}

I'm getting warning on function initalize which is 'Type safety: The expression of type ... needs unchecked conversion to conform to ...'.

I can get rid of this with using suppresswarning but I do not want to use it. What am I missing ?

Thanks in advance...

like image 537
Vivian Maya Avatar asked Jun 02 '15 13:06

Vivian Maya


1 Answers

public interface abc<T extends JPanel> {
    public T initalize();
}

public class Startup_thePanel extends JPanel implements abc<Startup_thePanel> {
   public Startup_thePanel initalize() {

            return this;
    }
}

this would make the compiler to know which type of interface your are implementing.

like image 88
Eugen Halca Avatar answered Nov 14 '22 21:11

Eugen Halca