type inference

Brian Goetz brian.goetz at oracle.com
Wed Mar 14 22:57:11 PDT 2012


Type inference has been available in Java for quite some time; it was introduced in Java 5 to support generic methods, and then extended in Java 7 with the "diamond" feature.  It is being extended further in Java 8 in several ways -- refinement of the basic type inference algorithm (to support type inference in more contexts, such as using diamond in method invocation contexts), and inferring formal parameters of lambdas from the target type.  

We will NOT be taking it as far as allowing you to omit type declarations on variables (such as allowing "var x = ...", as C# or Scala does).  Instead we allow removal of type information at the *use* site when it can be inferred from declarations, rather than allowing type-less declarations.  

On Mar 14, 2012, at 7:45 PM, Chance wrote:

> On Wed, Feb 22, 2012 at 8:28 AM, Maurizio Cimadamore
> <maurizio.cimadamore at oracle.com> wrote:
>> As Brian said, details of type-inference are being figured out as we
>> speak. The design space is, as you can imagine, fairly big, and
>> solutions might vary from a full-blown global type-inferencer  (a la ML)
>> to strategies that work in a more local environment. We think that the
>> latter strategies have better chance of succeeding in the Java ecosystem
> 
> Is type inference being added only as it relates to lambdas or as a
> general language feature so that you could declare a String as:
> s = "hey";
> 
> Chance
> 



More information about the lambda-dev mailing list