Prev | Current Page 226 | Next

Jon Skeet

"C# in Depth: What you need to master C# 2 and 3"

Existing classes can reasonably easily be ???upgraded??? to generic versions.
?–  The previous feature has been utilized quite effectively with the reflection system
??”java.lang.Class (the equivalent of System.Type) is generic, which
allows compile-time type safety to be extended to cover many situations involving
reflection. In some other situations it??™s a pain, however.
?–  Java has support for covariance and contravariance using wildcards. For
instance, ArrayList can be read as ???this is an ArrayList of
some type that derives from Base, but we don??™t know which exact type.???
111 Summary
My personal opinion is that .NET generics are superior in almost every respect,
although every time I run into a covariance/contravariance issue I suddenly wish I
had wildcards. Java with generics is still much better than Java without generics, but
there are no performance benefits and the safety only applies at compile time. If
you??™re interested in the details, they??™re in the Java language specification, or you
could read Gilad Bracha??™s excellent guide to them at http://java.sun.com/j2se/1.5/
pdf/generics-tutorial.pdf.
3.7 Summary
Phew! It??™s a good thing generics are simpler to use in reality than they are in description.
Although they can get complicated, they??™re widely regarded as the most important
addition to C# 2 and are incredibly useful.


Pages:
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238