相关疑难解决方法(0)

如何在java中为泛型类创建通用构造函数?

我想以通用的方式创建一个KeyValue类,这就是我写的:

public class KeyValue<T,E> 
{

    private T key;
    private E value;
    /**
     * @return the key
     */
    public T getKey() {
        return key;
    }
    /**
     * @param key the key to set
     */
    public void setKey(T key) {
        this.key = key;
    }
    /**
     * @return the value
     */
    public E getValue() {
        return value;
    }
    /**
     * @param value the value to set
     */
    public void setValue(E value) {
        this.value = value;
    }

    public KeyValue <T, E>(T k , E …
Run Code Online (Sandbox Code Playgroud)

java generics

61
推荐指数
1
解决办法
8万
查看次数

标签 统计

generics ×1

java ×1