Forum Stats

  • 3,872,214 Users
  • 2,266,407 Discussions


Generic syntax

843793 Member Posts: 41,732 Green Ribbon
edited Aug 18, 2002 8:58PM in Generics
Hey, I just realized what generics are ;)

I think the angle bracket syntax for generics are ugly. Why not have a MagicType class that does not have to be casted? All the data structures can have an optional Class[] parameter that says what classes are allowed.

GenericList list = new GenericList(new Class[] { String.class });
String a = list.remove(0);
GenericList's psuedocode would look like this:
class GenericList {
   public GenericList(Class[] types) {
      // save the types in an instance variable.
   public void add(Object a) {
      // check if a instanceof types[x], if not, throw RuntimeException
   public MagicType remove(int index) {
     // MagicType is an Object that automatically casts to something
     return objectAtIndex(index);


  • brucechapman
    brucechapman Member Posts: 466

    I'm all for re-inventing wheels. without that we wouldn't have pneumatic spoked ones, and my bicycle would be built by a stone mason, and I'd need a bullock to take me anywhere.

    However, we established years ago that round (not square) is the ideal shape. Each re-invention should proceed from current knowledge. Check out and and then if you can improve on that, let the expert group know.
This discussion has been closed.