Skip to Main Content

Java APIs

Generic syntax

843793Aug 18 2002 — edited Aug 18 2002
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);
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 15 2002
Added on Aug 18 2002
1 comment