Any plans to support type-safe access to java.lang.Method?

Behrang Saeedzadeh behrangsa at gmail.com
Mon Jun 20 05:58:12 PDT 2011


Hi Brian!

Yes I am exactly referring to that. While I am not a big fan of
evolving Java's syntax, the over abuse of generics in JPA 2.0's
type-safe criteria builder API make me wish Java had supported them.

Cheers,
Behrang Saeedzadeh
http://www.behrang.org



On Mon, Jun 20, 2011 at 10:05 AM, Brian Goetz <brian.goetz at oracle.com> wrote:
> He's talking about something along the lines of the Coin proposal "Method
> and Field literals".  (The # notation is taken from the strawman syntax for
> lambdas in Java SE 8.)  The idea is that there'd be some
> {Method,Field}-valued expression like "ClassName#methodName" where the
> compiler verified the method was there and then emitted the appropriate
> reflective goo (catching reflective errors and wrapping them as runtime
> exceptions, since you now have some reason to believe the symbol actually
> exists (that's the type-safe part.)  It would let you write APIs that
> abstract more easily over member references.
>
> The answer is: no, we're not considering this at this time.
>
>
>
> On 6/19/2011 4:53 PM, Erik Trimble wrote:
>>
>> On 6/19/2011 5:07 AM, Behrang Saeedzadeh wrote:
>>>
>>> Hi all,
>>>
>>> Are there any plans to support type-safe access to methods?
>>>
>>> For example something like:
>>>
>>> java.lang.Method toString = Object#toString();
>>>
>>> It would make writing APIs like JPA 2's type-safe criteria builder
>>> more concise and readable.
>>>
>>>
>>> Cheers,
>>> Behrang Saeedzadeh
>>> http://www.behrang.org
>>
>> Behrang,
>>
>> Exactly what do you mean? While Java (AFAIK) isn't a provably type-safe
>> language (as such formal proofs are very difficult for most complex
>> languages), it already has both runtime and compile time type checking,
>> and does fit the practical description of a type-safe language. That is,
>> Java already has type-safe access to methods.
>>
>> http://www.securingjava.com/chapter-two/chapter-two-10.html
>>
>> Also, the '#' sign isn't any sort of Java operator. I'm assuming that it
>> comes from Perl (I though maybe C#, but it doesn't have it either), but,
>> given the syntax, that doesn't make sense either. I don't understand the
>> right side of your example, as I don't know what it's trying to
>> accomplish.
>>
>> Also, since Java is a polymorphic language, you wouldn't want *too*
>> strong a type-checking system, as I would always want the ability for a
>> method to work on a subclass of any parameter I had defined the method
>> as accepting.
>>
>>
>


More information about the jdk8-dev mailing list