Accessing static members on type variables

Raffaele Sgarro raffaelesgarro at gmail.com
Fri Apr 4 20:39:28 UTC 2014


Because I put online the sample with a field, but my original case used a
method.


2014-04-04 21:56 GMT+02:00 Alex Buckley <alex.buckley at oracle.com>:

> Your code said T.FIELD, which is a field access dependent on the members
> of type T. I don't know why you're looking at method invocation.
>
>
> On 4/4/2014 12:52 PM, Raffaele Sgarro wrote:
>
>> Thanks guys.
>>
>> Already seen that paragraph of 4.4, and despite the vague warning, I
>> assumed it was ok and tried to understand how the call is dispatched. So
>> I looked into /"15.12.1. Compile-Time Step 1: Determine Class or
>> Interface to Search"/, but:
>>
>>   *
>>
>>       If the form is /TypeName/ |.| /[TypeArguments]/ /Identifier/, then
>>     the type to search is the type denoted by /TypeName/.
>>
>>   *
>>
>>       If the form is /ExpressionName/ |.| /[TypeArguments]/
>>     /Identifier/, then the class or interface to search is the declared
>>     type T of the variable denoted by /ExpressionName/ if T is a class
>>
>>     or interface type, or the upper bound of T if T is a type variable.
>>
>>   *
>>
>>       If the form is /Primary/ |.| /[TypeArguments]/ /Identifier/, then
>>     let T be the type of the /Primary/ expression. The class or
>>
>>     interface to search is T if T is a class or interface type, or the
>>     upper bound of T if T is a type variable.
>>
>>
>> I know it's difficult to dig into "Section 6: Names", and that's just
>> for curiosity's sake, but it'd be very interesting to know how things go
>> on from this point. BTW, I tried javac8, javac7 and JDT, and all three
>> exhibit the same behavior.
>>
>>
>> 2014-04-04 20:47 GMT+02:00 Remi Forax <forax at univ-mlv.fr
>> <mailto:forax at univ-mlv.fr>>:
>>
>>
>>     On 04/04/2014 08:20 PM, Alex Buckley wrote:
>>
>>         Membership of the type variable T is specified by JLS 4.4 and
>>         4.9. The members of T are the same as the members of a class QQQ
>>         whose direct superclass is Outer. Since QQQ would inherit FIELD
>>         from Outer, T has a member FIELD. There is nothing special about
>>         FIELD being static.
>>
>>         Alex
>>
>>
>>     My bad, I've read the email of Raffaele too fast,
>>     I was thinking of bug 7022052, see
>>     https://bugs.openjdk.java.net/__browse/JDK-7022052
>>
>>     <https://bugs.openjdk.java.net/browse/JDK-7022052>
>>
>>     Anyway, it's quite ugly.
>>
>>     Rémi
>>
>>
>>
>>         On 4/4/2014 12:54 AM, Raffaele Sgarro wrote:
>>
>>             Consider the following code (ideone <http://ideone.com/GtBQEy
>> >):
>>
>>             class  Outer{
>>                 public  static  final  String  FIELD=  "Success!";
>>             }
>>
>>             class  Test<Textends  Outer>{
>>                 public  String  test()  {
>>                   return  T.FIELD;
>>                 }
>>             }
>>
>>             Does the JSL allow a type variable T to be used to access
>>             static members
>>             of its upper bound?
>>
>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20140404/89660c22/attachment.html>


More information about the compiler-dev mailing list