2012-03-16 32 views
2
public interface IFoo<TKey, FooEntity<TValue>> { 
    // stuff 
} 

我得到这个错误:
类型参数FooEntity是隐藏式FooEntity类型参数FooEntity是隐藏式FooEntity

public class FooEntity<T> { 

    private T foo; 


} 

我怎样才能解决这一问题?

我希望能够在其他地方实现IFoo接口。

回答

3

看到这个:

public interface IFoo<TKey, FooEntity<TValue>> { 
    // stuff 
} 

你定义一个名为IFoo的接口。当定义一个类型时,<>之间的东西是类型参数。使用IFoo界面时应该提供实际的类型,而不是在定义IFoo时提供。

你真的是这样的:

public interface IFoo<TKey, TValue> { 
    void doSomething(TKey key, FooEntity<TValue> value); 
} 

而且

public class MyFoo implements IFoo<String, Integer> { 
    @Override 
    public void doSomething(String key, FooEntity<Integer> value) { 
     // TODO: .... 
    } 
} 
0

试试这个...

class FooEntity<K> { } 

interface IFoo<K,V> { } 

class IFooImplElseWere<K,V> implements IFoo<K,V> { } 

IFoo<String, FooEntity<String>> ifi = new IFooImplElseWere<String,FooEntity<String>>();