PROPOSAL: Method and Field Literals

Schulz, Stefan schulz at e-Spirit.de
Thu Mar 12 02:48:21 PDT 2009


Noel Grandin wrote:
> Stephen Colebourne wrote:
> > Field<Period> f = Period#ZERO;
> > Method<String> m = String#toUpperCase();
> >
> > public void process(Method<String> method) { ... }
> >
> > This allows frameworks to be specific about the type of method or
> > field they will accept.
> >
> >   
> 
> I can see the benefit for Field, but for Method I think you're wasting
> your time.
> 
> Frameworks will be more interested in the parameters of a 
> method rather
> then return type, but I can't see any way of encoding that into the
> generic parameters,
> because we can't do a variable number of type parameters.
> 
> I would rather leave Method as a raw type, possibly something to solve
> in the future when Java's generic type system becomes more 
> powerful :-)

I mostly agree. The return type of a method alone is of low value. I don't think, one wants to extend the generic type system so types can take generic definitions with variable number of parameters (at least not in the scope of this proposal). The issue of getting a method literal compile-time type-safe should be postponed until Java has method types.

Stefan



More information about the coin-dev mailing list