0

I have the following

public class bucket<String,Integer>{
    private Integer num;
    .
    .
    .
    public bucket(){
        num=new Integer(100);
    }
}

Eclipse spits out an error saying that it cannot instantiate the type Integer.
Why is it saying this?

3
Contributors
2
Replies
14
Views
3 Years
Discussion Span
Last Post by JamesCherrill
0

You probably have got confused about how to use generics.
You have defined type parameters for your class and named them "String" and "Integer". These names are hiding the classes with the same name, so on line 2 and 7 "Integer" is a type variable, not the Integer class.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.