Warning about single underscore identifier

Stephen Colebourne scolebourne at joda.org
Thu Aug 1 06:54:45 PDT 2013


I guess we have had backwards incompatible language changes before
(adding enum and assert keywords), although had thought it unlikely
that there would be any more. I assume the language spec actually
mandates the deprecation?!

The principle of removing crud is good, but why is underscore special.
I certainly think of some others that desparately need removal.
Deprecate them in 8 for removal in 9....

For example C style array locations,
  private String array[];
  private String process()[] {  }

or the lower case "l" suffix for long literals.

or octal literals (which are a pain in the backside for JSR-310, as
people wrongly write
  LocalDate.of(2013, 07, 01)
which works, but then find
  LocalDate.of(2013, 09, 01)
does not work, because they should never actually use the leading zero.

Stephen


On 31 July 2013 19:52, Brian Goetz <brian.goetz at oracle.com> wrote:
> Yes, we are "reclaiming" the syntactic real estate of "_" from the space of identifiers for use in future language features.  However, because there are existing programs that might use it, it is a warning for identifiers that occur in existing syntactic positions for 8, and an error for lambda formals (since there is no existing code with lambdas.)
>
> Your suspicion is mostly right, except that we are certainly NOT going to do Scala's "wunderbar".  However, things it might be used for include things like "I don't want to give this variable a name" (such as catch parameters that are never used.)
>
>
> On Jul 29, 2013, at 6:59 AM, Roel Spilker wrote:
>
>> Hi all,
>>
>> If I compile a java program containing an identifier consisting of just a
>> single underscore using the java 8 compiler, I get the following warning:
>>
>> warning: '_' used as an identifier
>> (use of '_' as an identifier might not be supported in releases after Java
>> SE 8)
>>
>> I suspect this is to allow for scalaesc parameters in lambdas.
>>
>> Can someone confirm my suspicion? Is this still relevant or is this a
>> left-over from an early design? Is there a valid reason to not support '_'
>> for all identifiers, or can it be only restricted for identifiers inside
>> lambdas, and therefore guaranteed new code, to maintain backwards source
>> compatibility.
>>
>> Roel
>>
>
>


More information about the lambda-dev mailing list