About an instance of the Vector class and add an element

2009-12-15_172535

不知是我英文不好不懂题意,还是这个题目出的有问题,让我看了答案有点疑问?

答案是这样:

4) Vector v=new Vector(100);
v.addElement(“99”)

A vector can only store objects not primitives. The parameter “99” for the addElement method pases a string object to the Vector. Option 1) creates a vector OK but then uses array syntax to attempt to assign a primitive. Option 2 also creates a vector then uses correct Vector syntax but falls over when the parameter is a primitive instead of an object.

为什么我用eclipse 3.5.1+java 1.6来编译,2,3,4都可以执行,感觉add是指增加一个元素,而addElement可以增加较多个,但在此例是一样的,另外解答说不可以使用primitive型别,可是却又可以使用,但查考手册没有特别提到不可以,所以这个说明就有点奇怪了,看倌是否有更好说明可以帮我了解的!