Re: Generics Question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Scott M. wrote:

I do get your point and I haven't misunderstood anyting (you or the author
of the book I'm reading). You've misunderstood what I'm asking.

Scott, I think I understand what you've misunderstood. I think you
somehow got the idea, once upon a time, that generics enable a certain
class of solutions, where such solutions are semantic in nature (e.g.
write a class that can "maintain a list of stuff", etc.). Now, you've
stumbled across interfaces, and it's dawned on you that you can use
interfaces to do the same semantic thing ("maintain a list of stuff" so
long as "stuff" implements the interface) and you're seeing a semantic
equivalence here.

The thing is, the feature that generics brings to the table, isn't this
capability to implement certain semantics (and thus being equivalent or
a subset of interfaces); it's rather that it enables such semantics *in*
*a* *statically-typed* *way* - and this is the very feature that
interfaces / polymorphism *doesn't* provide. They only work with dynamic
typing.

The fact is that (per my first reply to you) I *can* pass a parameter to my
type that (mechanically) acts as <T> would in a parameterized type.

A parameterized type is a type constructor. By passing it type
arguments, you're creating what effectively is a *new* type, statically
checked at compile time. You *cannot* create such a new type by passing
an interface reference to a constructor.

You know the features that generics bring to the table, but you're
thinking in terms of end results, i.e. observable program actions, and
you can see that interfaces (or ever System.Object) can do the same
thing. But the trouble is, that isn't what generics are about - they
aren't about enabling new kinds of end results, to the exclusion of
other possible implementations. They're all about static typing. Plain
and simple.

-- Barry

--
http://barrkel.blogspot.com/
.



Relevant Pages

  • Re: Interfaces and abstract tagged types
    ... These 3 cases represent an implementation view on inheritance. ... interfaces and implementations. ... This multiplies the same code by the factor of W**D where W is the tree ... In order to handle this exponentially exploding code, generics are ...
    (comp.lang.ada)
  • Re: generic oversight?
    ... As a 'full' user of generics, as far as I know, I don't need the? ... My new interfaces might not be useful with the? ... > giving advice on newsgroups that assumes that Joshua Bloch is an idiot. ... I did not say ANYTHING against Joshua Bloch. ...
    (comp.lang.java.programmer)
  • Re: Interfaces and abstract tagged types
    ... Interfaces are for run-time polymorphism, ... Generics is just an aid to do it in a handy way. ... due to lack of good UML tools for Ada 2005? ... Clearly, when you inherit, you do ...
    (comp.lang.ada)
  • Re: Are templates usefull?
    ... With interfaces and generics, they are a way of specifying the specific ... an erroneous cast will be caught at run-time, not compile time. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: No Equals on interfaces
    ... >> The OP's sample IMO didn't make sense. ... for interfaces which is definitely not true and thus misleading. ... semantics put on them in general .NET terminology. ... There is nothing implicit for events in VB. ...
    (microsoft.public.dotnet.languages.vb)