简体   繁体   中英

java wildcard type safety warning

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...

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.

try this

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


public class Startup_thePanel extends JPanel implements abc<Startup_thePanel> {

    private static final long serialVersionUID = 1L;

    @Override
    public Startup_thePanel initalize() {

            return this;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM