Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6840638

Project Coin: Improved Type Inference for Generic Instance Creation (aka 'diamond')

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P3 P3
    • 7
    • 5.0, 7
    • tools
    • b72
    • generic, unknown, x86
    • generic, windows_xp
    • Verified

      One of the language changes in Project Coin is allowing inference on constructor call through the <> notation (aka 'diamond'); this bug tracks that work.

      SUMMARY OF THE PROPOSAL

      This proposal addresses the addition of limited type inference for
      class instance creation expressions to the Java programming language.
      In cases where parametrized types need to be explicitly declared for a
      constructor, and the full parametrized type < T1 , T2 , ...Tn > of
      that constructor is obvious from the context, then the parameterized
      type of the constructor can be replaced with an empty set of type
      parameters: <>. The <> construct is legal to use when constructing an
      ob ject and either assigning it to a variable, or when passing it as
      a parameter.

      For example, consider the following assignment statement:

      Map<String, List<String>> anagrams = new HashMap<String, List<String>>();

      This is rather lengthy, so it can be replaced with this:

      Map<String, List<String>> anagrams = new HashMap<>();

            mcimadamore Maurizio Cimadamore
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: