Introduction and RFC

Andras Gerlits andras.gerlits at gmail.com
Sat Oct 13 08:26:49 PDT 2007


Hi all,

I'm new to the list, so I'd like to say hello first.

I am a developer working almost exclusively with Java and related technologies.

The reason I joined this list is that I would like some opinions on
the following proposal (some first-level review by folks much
knowledgable about the java compiler than myself):

The following examples demonstrate the usage of a new, generic
wildcard which I always thought was a missing feature of the generics
framework and which would allow _some_ basic level of polymorphism
when programming with generics.

The wildcard is represented by a tilde '~', meaning the first
encapsulating class of the instance implementing the method.

It might only be allowed for top-level classes, (for the sake of
simplicity) but all these are just ideas for which I am fishing for
thoughts.

/**
* ~ stands as a generic wildcard for the class it was invoked on.
*
*/
public abstract class Animal implements Cloneable {

     protected static final int NUMBER_OF_DESCENDENTS = 10;

     public List<~> children() {
           //create list

           for(NUMBER_OF_DESCENDENTS) {
                 list.add(this.clone());
           }

           //return list
     }
}


public class Dog extends Animal {
     //specific implementation, does not override children
}

Any thoughts would be appreciated.

Thanks,
Andras Gerlits
Valid examples of usage:

//Any code using API
Dog dog = new Dog();
List<Dog> puppies = dog.children();

Animal dogButDeclaredAsAnimal = new Dog();
List<Animal> babies = dogButDeclaredAsAnimal.children();



Invalid example of usage:

Animal dogButDeclaredAsAnimal = new Dog();
List<Dog> babies = dogButDeclaredAsAnimal.children();



More information about the compiler-dev mailing list