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

Erik Trimble erik.trimble at oracle.com
Sun Jun 19 13:53:14 PDT 2011


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.


-- 
Erik Trimble
Java Platform Group Infrastructure
Mailstop:  usca22-317
Phone:  x17195
Santa Clara, CA
Timezone: US/Pacific (UTC-0800)



More information about the jdk8-dev mailing list