this pisses me of because i think i'm thinking about stuff from a C perspective where type stuff has to be rigid, so <> isn't the type it's like, what, a pretend type? it's the ole classic primitive integer set type of course
@augustus It's a specific instance of a generic type. Instead of the HashMap basically accepting "void *" pointers, this is an instance of the HashMap type that takes Integer pointers as the key, and a specific instance of Set as the value. This instance of Set accepts only Character instead of any old random Object.
@augustus It's "generic" because you write the source for the implementation once, and it works regardless what types you chuck in there. In Java, the binary implementation is the same too, because of "type erasure" -- the bytecode actually just has Object everywhere and only the compiler cares about the type. In C++, C# and D you get separate compiled instances of the type specialized for the types you put in there, and with D you can even provide conditionals that need to be fulfilled for the types that are allowed in the slots.
@clacke isn't it dangerous to give them the ability to hold things of any type, like what if the object tries to do something with them that some types accept and others don't, or does that not count since they're all really object wrapper and not types, would you just have to build it in a way to be able to deal with anything
@augustus In Java, it's basically just for container types, so the generic method or class doesn't really do anything with the objects except compare their identities, store references to them and return them. I think that's what you were saying, too.
In D, since you can specify what kind of things you can accept as types, you can do more specific things to them, and even assume things about them like some methods being memory-safe etc, because those are attributes you can require too.
@augustus In Java, if you have more specific things you want to do to an object, you put an interface as the type, and then you've lost the need for generics. Or maybe you might have wanted to specify the type even further at compile time but anyway, you can't. :-)