Type inference of parameters

Kieron.Wilkinson at paretopartners.com Kieron.Wilkinson at paretopartners.com
Thu Jul 15 08:40:17 PDT 2010

Brian Goetz wrote on 07/07/2010 19:18:14:
> Yes.  I, for one, am in favor of type inference :)
> Type inference is a key underlying motivator for a number of JDK 7 
> changes, including lambda and diamond.  We are all about static typing, 
> that doesn't mean that the user has to laboriously write out every 
> single type 
> declaration when it is obvious from the context.

This is a really exciting (and unexpected) development. I definitely vote 
for this!

I'd be interested to know how far this goes (or how far it is intended to 
go). Will it be able to infer the types from generic parameters like Scala 
does? For example, given a "map" method defined in a List<A> class:

  public <B> List<B> map(Function<A, B> function);

Could I write something like the following?

  List<Animal> animals = ...
  List<Food> foods = animals.map({ a -> a.getFood() });

Rather than:

  List<Food> foods = animals.map({ Animal a -> a.getFood() });


We use our own collection library that has Function-like classes used for 
fold/map/etc, and it would be great if we didn't have to put in type 
annotations where they are obvious (especially helpful with multiple 
parameters or long class names).


This message may contain confidential and privileged information and is intended solely for the use of the named addressee. Access, copying or re-use of the e-mail or any information contained therein by any other person is not authorised. If you are not the intended recipient please notify us immediately by returning the e-mail to the originator and then immediately delete this message. Although we attempt to sweep e-mail and attachments for viruses, we do not guarantee that either are virus-free and accept no liability for any damage sustained as a result of viruses.

Please refer to http://www.bnymellon.com/disclaimer/piml.html for certain disclosures.

More information about the lambda-dev mailing list