View Single Post
Old Nov 25th, 2005, 4:02 PM   #6
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by säkki
well it actually isn't descended from List<Person>, if I understand what you mean. cInd contains three kind of "persons" could be like this:
cInd {Person("FN", "LN"), Student("FN", "LN"), Worker("FN", "LN")} <- not meant to be anykind of syntax just to clarify things.
Student and Worker are descended from Person.
Java 1.5 has a new feature called generics, which, amongst other things, allows you you to tie a type to a container

Before Java 1.5, you had to cast an element as the correct type when removing it from a container:
Vector list = new Vector();
list.add("Hello");
list.add("World");
String lastElement = (String)list.get(0);
In Java 1.5, you can use generics to tell the JVM which type to expect from a container:
Vector<String> list = new Vector<String>();
list.add("Hello");
list.add("World");
String lastElement = list.get(0);
The class Vector<Person> will take Persons, and descedants of Persons (ie. Workers and Students).
Vector<Person> persons = new Vector<Person>();

persons.add(new Person("A", "B"));
persons.add(new Worker("A", "B"));
persons.add(new Student("A", "B"));

for (Person person : persons) {
   System.out.println(person);
}
Of course, if you're not using Java 1.5, you can safely ignore all this talk about generics.

Quote:
Originally Posted by säkki
Thanks for these tips allready, I'll try to get forward in this but I really am miserable in this.
You seem to be doing okay so far
Arevos is offline   Reply With Quote