Using int as a type parameter for java.util.Dictionary

后端 未结 6 2133
孤独总比滥情好
孤独总比滥情好 2021-02-06 22:51

When I try to declare a Dictionary as such:

private Dictionary map;

The compiler gives me the following error:

6条回答
  •  一生所求
    2021-02-06 23:16

    In Java primitives aren't objects, so you can't use them in place of objects. However Java will automatically box/unbox primitives (aka autoboxing) into objects so you can do things like:

    List intList = new LinkedList();
    intList.add(1);
    intList.add(new Integer(2));
    ...
    Integer first = intList.get(0);
    int second = intList.get(1);
    

    But this is really just the compiler automatically converting types for you.

提交回复
热议问题