"For example, if the department of motor vehicles supplies a list of
drivers to the census
bureau, this seems reasonable. We think that a List<Driver> is a
List<Person>,
assuming that Driver is a subtype of Person. In fact, what is being
passed is a copy
of the registry of drivers. Otherwise, the census bureau could add new
people who are
not drivers into the list, corrupting the DMV’s records."
http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf
What do they mean by a "copy of the registry" of drivers? Certainly
people who aren't drivers shouldn't be in the list of drivers, only
those who extend or implement Driver should be in that list.
what's being passed to what in that sentence?
thanks,
Thufir
Tommy Halsbrekk - 23 Jun 2008 10:41 GMT
> What do they mean by a "copy of the registry" of drivers? Certainly
> people who aren't drivers shouldn't be in the list of drivers, only
> those who extend or implement Driver should be in that list.
>
> what's being passed to what in that sentence?
I havent read the entire tutorial, but they use the DMV example a couple
of times in the tutorial, its just a generic example.
In a real life DMV situation you would not get access to their actual
database, you would get a copy only. But in the generics example you
would get direct access and thats a problem because then you can start
inserting data into the list that does not conform to the original
intent of the list.
So when reading the rest of the tutorial, they explain how you can avoid
this problem with generics.
regards
tommy
Roedy Green - 23 Jun 2008 11:44 GMT
On Sun, 22 Jun 2008 21:39:55 -0700 (PDT), Thufir
<hawat.thufir@gmail.com> wrote, quoted or indirectly quoted someone
who said :
>bureau, this seems reasonable. We think that a List<Driver> is a
>List<Person>,
You might make two versions of a Class, one that is immutable. If you
want read-only access, you use the immutable version to avoid
inadvertently modifying the master copy. This would make more sense
with a POD where changes to RAM object result in permanent changes.
See http://mindprod.com/jgloss/pod.html
Driver is likely a subclass of Person. It has more fields. However
there would be fewer Driver records in the universe than Person
records. Every Driver would also be a Person. Either Driver extends
Person (isa) or Person has an optional field to point to the Driver
extension fields (hasa).
see http://mindprod.com/jgloss/isa.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Lew - 24 Jun 2008 20:02 GMT
> "For example, if the department of motor vehicles supplies a list of
> drivers to the census
[quoted text clipped - 9 lines]
>
> What do they mean by a "copy of the registry" of drivers?
The "registry of drivers" is the List<Driver>.
I don't find the source you cite to be the most clearly worded.
The point they're trying to make is that List<Driver> is not a subtype
of List<Person> even though Driver might be a subtype of Person.
If List<Driver> were a subtype of List<Person>, it would be possible
to add a Person to the List<Driver>. That would cause weirdness if
that Person instance were not also a Driver.
Don't let the confusion of the example obscure the point.
Let's use 'C' (meant to look like a "subset" symbol) to mean 'is a
subtype of'.
The point the tutorial wants to make is:
(Driver 'C' Person) DOES NOT IMPLY (List<Driver> 'C' List<Person>)
--
Lew