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?

Recommended Answers

All 2 Replies

ehm ... why do you have <String, Integer> in your class definition?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.