开发者

Java Interface implementation problem

I have problem with sets. Required java.lang.String found String... What can i do there?

public 开发者_StackOverflowinterface Node {
        public <V> V get();
        public <V> void sets(V value);
    }

public enum MIBNodes implements Node {

    TEST {
         private String e;
        @Override
        public String get() {
            return "aa";
        }

        @Override
        public <String> void sets(String value) {
           e=value;
        }




    };


};

UPDATE

Each enum instance like TEST , TEST1 ... may have different type.. String, Integer or anyother... So public enum MIBNodes implements Node { cant become public enum MIBNodes implements Node<String> {


This is the Problem:

@Override
public <String> void sets(String value) {
        ^^^^^^
    e=value;
}

Here, String is a type variable (a re-definition of V), not a java.lang.String. And I don't really think you can fix that without changing your design:

public interface Node<V> {
    public V get();
    public void sets(V value);
}

And in case you want your enum to be generic : that's impossible. Different enum items can't implement the same interface with different generic parameters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜