Generation of synthesized parameters

Alex Buckley alex.buckley at oracle.com
Wed Jan 30 14:12:29 PST 2013


On 1/30/2013 12:47 PM, Peter Jensen wrote:
> On 01/29/13 17:14, Alex Buckley wrote:
>> Constructs declared implicitly in source code are:
>>
>> - default constructors (8.8.9)
>> - the initial parameters of constructors for non-private inner member
>> classes and anonymous classes (13.1, 15.9.5.1)
>
> Did you mean "non-static" ?

Inner member classes are non-static by definition. I really did mean 
non-private.

> Local classes constructors also gets an initial parameter.

Yes, but Joe explained (using the phrase "named inner classes" rather 
than "local classes") why such a parameter is synthetic 
(implementation-dependent) rather than synthesized 
(implementation-independent).

Alex

>> On 1/29/2013 12:14 PM, Joe Darcy wrote:
>>> Hello,
>>>
>>> On 1/29/2013 11:40 AM, Eric McCorkle wrote:
>>>> In order to facilitate writing tests for the MethodParameters feature,
>>>> I'd like to get a complete list of all the cases when javac can
>>>> generate
>>>> synthesized parameters.
>>>>
>>>> Here is a list I've put together from email discussions and comments
>>>> in JBS:
>>>>
>>>> 1) outer "this" parameters
>>>
>>> Arguably, some outer this parameters would be *synthesized* with others
>>> would be *synthetic*.
>>>
>>> Inner classes that are also member classes, (see diagram in "Nested,
>>> Inner, Member, and Top-Level Classes,"
>>> https://blogs.oracle.com/darcy/entry/nested_inner_member_and_top), are
>>> potentially callable from outside of the enclosing class and are
>>> required to have an outer this parameter as the first parameter so that
>>> code from different compilers can call each other.  The other this
>>> parameter in this case is *synthesized* as it is mandated or implied by
>>> the JLS.
>>>
>>> On the other hand, named inner classes defined inside a method or
>>> constructor as well as anonymous classes only need to obey a
>>> compiler-internal contract and any extra parameters in this case are
>>> *synthetic*.  (Not all anonymous classes have an outer; an anonymous
>>> class created inside a static initializer block does not.)
>>>
>>>
>>>> 2) extra values passed to constructor for enum values
>>>
>>> Such parameters are *synthetic*, they are a javac implementation
>>> artifact not mandated or implied by the JLS.
>>>
>>>> 3) hidden values passed to constructors of inner classes for final
>>>> variables
>>>
>>> You'll can check the JLS regarding whether these are synthesized or
>>> synthetic, but I would assume they are synthetic.
>>>
>>>> 4) JLS mandated public no-arg constructors added by the compiler to
>>>> classes with no declared constructor: synthesized
>>>
>>> This is not a parameter, but another language structure.
>>>
>>> HTH,
>>>
>>> -Joe
>>>
>>>> 5) The two parameters pre-ended to enum constructors by javac
>>>>
>>>>
>>>> Does this capture everything, or does it miss something?
>>>>
>>>> Ideally, I would like to put together a complete list of all cases that
>>>> should generate synthesized parameters.  (If one already exists, then
>>>> that's great).
>>>>
>>>> Thanks,
>>>> Eric
>>>
>



More information about the compiler-dev mailing list