Ericson Willians
Ericson Willians

Reputation: 7845

Why Netbeans does not find the methods of an interface instance?

I have a class:

public class JWHTMLPage implements JWDisplayable {
    ...
}

An Interface:

public interface JWDisplayable {
    
    public void addCSS(String link);
    public void addJS(String link);
    public void setViewport(String content);
    public void appendToBody(String html);
    public void updateHTML();
    
}

And another class:

public class JWHTMLPageMap<String, JWHTMLPage> implements Map<String, JWHTMLPage>, JWDisplayable {
    ...
}

Inside JWHTMLPageMap, I override the addCSS method. The problem is that NetBeans's autocomplete does not find the methods of JWHTMLPage:

enter image description here

It treats page as just an Object, but it's a JWHTMLPage, which implements all those methods in JWDisplayable. What am I doing wrong?? It makes no sense.

Upvotes: 1

Views: 841

Answers (1)

alainlompo
alainlompo

Reputation: 4434

Your problem certainly comes from this line:

public class JWHTMLPageMap<String, JWHTMLPage> implements Map<String, JWHTMLPage>, JWDisplayable {

You may not have a compilation error with it but it is not correct for your are using existing classes as though they were formal generecity parameters and the real class will then be hidden by the generic parameters

So instead use:

public class JWHTMLPageMap<S extends String, J extends JWHTMLPage> implements Map<S, J>, JWDisplayable {

Which may generate a warning that says something like: The type parameter S should not be bounded by the final type String. Final types cannot be further extended (because String is a final type)

Therefore why don't you simply write:

public class JWHTMLPageMap<J extends JWHTMLPage> implements Map<String, J> , JWDisplayable {

Upvotes: 1

Related Questions