Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-481

New ErrorRule to fix compiler error on initialization of var type variable with array

    XMLWordPrintableJSON

Details

    Description

      Below statement throws compiler error.

      var arr = {1,2};

      : error: cannot infer type for local variable var k = { 1 , 2 }; ^

      (array initializer needs an explicit target-type)

       

      Proposed fix would be

       int[] arr = { 1, 2 };

      The fix will be provided for Numeric primitive type array or for array with homogeneous members.

      a)Homogeneous type 
      1. var arr =  { new Object(), new Object()};
      fix: Object[] arr = { new Object(), new Object()};

       

       

      2. var arr = {"hello", "world"};
      fix: String[] arr = {"hello", "world"};

      b)Primitive Type Numeric array
      var arr = {1,2.2};
      fix: double[] arr = {1,2.2};

       

      PR Link:

      https://github.com/apache/incubator-netbeans/pull/519

      Attachments

        Issue Links

          Activity

            People

              arunava.sinha ARUNAVA SINHA
              arunava.sinha ARUNAVA SINHA
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 3h
                  3h