高级编程语言 Java之集合与对象
高级编程语言 Java之集合与对象(中文2900字,英文2100字)
如果程序只包含固定数量的对象,并且其生命周期都已知,那么这个程序就实在太简单了。
通常,你的程序会根据运行时才知道的条件创建新对象。不到运行期,不会知道所需对象的数量,甚至不知道确切的类型。为解决这个普遍的编程问题,需要能够在任意时刻,任意位置,创建任意数量的对象。所以,你就不能指望创建具名的引用来持有每一个对象:
High-level programming language Java Collections of
Objects
It’s a fairly simple program that has only a fixed quantity of objects with known lifetimes.
In general, your programs will always be creating new objects based on some criteria that will be known only at the time the program is running. You won’t know until runtime the quantity or even the exact type of the objects you need. To solve the general programming problem, you need to be able to create any number of objects, anytime, anywhere. So you can’t rely on creating a named reference to hold each one of your objects: [资料来源:http://doc163.com]
MyObject myReference;
since you’ll never know how many of these you’ll actually need.
[资料来源:www.doc163.com]