[Mono-list] How do I reference generic classes in C#???
muchomuse at gmail.com
Tue Jan 13 16:58:53 EST 2009
Uh oh, I feel like this is turning into a Java vs. DotNet culture debate
here, and I really don't care enough about either side to get into that. All
I'm saying is that I like the way Java lets you directly access a generic
class without refering to the type in it. Don't like my example? Fine, make
it static Mug.MugsInUse, which is incremented each time a constructor is
called. Unlike topology, that would change. My point is the same. Now could
that be done another way? Sure. I could have a MugInUse counter class or
whatever. At a technical level, it doesn't matter, it would work as well,
there are a million ways to make it work. Its about what's intuitive, what
sits easy in the mind. And what sits easy in my mind is that, a List is a
List whether its of groceries or things to do, and a Mug is a Mug whether it
has Cocoa in it or Coffee. And I should be able to refer to a List or Mug as
an entity regardless of what they contain.
But whatever, this is just my observation. And I'm pretty new to DotNet, I
may yet "see the light". Give me 6 months of getting used to DotNet and if I
still see things the same way, I'll come back and we'll have a real debate
on it. :)
On Sun, Jan 11, 2009 at 8:49 PM, Chris Howie <cdhowie at gmail.com> wrote:
> On Sun, Jan 11, 2009 at 2:07 AM, Luke B <muchomuse at gmail.com> wrote:
> > Huh. Yeah, I don't really know the history of Generics in each language.
> > assuming there's value in the .NET model, but I still find the Java model
> > more intuitive to program in. The reason is that I think of Generics as
> > something that are "contained" in a class, while being separate of the
> > class. So something like:
> > Mug<Cocoa> yourdrink = new Mug<Cocoa>();
> > Mug<Coffee> mydrink = new Mug<Coffee>();
> > Mug.topology = Doughnut;
> > makes more sense, I the general shape of all Mugs shouldn't be dependent
> > what liquid they contain. I can see the value of the dotnet approach too,
> > but its just simply less intuitive.
> I disagree entirely, and I was a Java developer long before I learned
> C#. I find the Java system incredible mind-bending and the only
> difficulty I had transitioning to the .NET model of generics was
> unlearning the Java model (which was a joy). There is nothing worse
> than enforcing the use of .equals and friends over what should
> effectively be primitive types, but are actually objects. And, of
> course, there's the memory footprint you create by boxing primitives
> for no good reason.
> What you're specifying there, by the way, actually doesn't even make
> sense since data like that would be better exposed in a property (or
> getter method, if we're talking Java) since it's not something you
> would expect to be able to set about all Mugs that exist in an
> application all at once.
> Chris Howie
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Mono-list