Friday, March 18, 2011

Reflection API gripes

java.lang.Method and java.lang.Constructor are strikingly close in concept. For all intents and purposes Constructors are little more than syntactic sugar. Yet there is no API acknowledgement of many their similarities.

Yes, they share some common interfaces and the same super class, but when you peal away the methods that are not accounted for by interfaces and superclasses, here's what you get:

java.lang.reflect.Constructor
public T newInstance(Object ... initargs)
public Annotation[][] getParameterAnnotations()
public Class[] getExceptionTypes()
public Class[] getParameterTypes()
public String toGenericString()
public Type[] getGenericExceptionTypes()
public Type[] getGenericParameterTypes()
public boolean isVarArgs()
java.lang.reflect.Method
public Object getDefaultValue()
public Object invoke(Object obj, Object... args)
public Class getReturnType()
public boolean isBridge()
public Type getGenericReturnType()
public Annotation[][] getParameterAnnotations()
public Class[] getExceptionTypes()
public Class[] getParameterTypes()
public String toGenericString()
public Type[] getGenericExceptionTypes()
public Type[] getGenericParameterTypes()
public boolean isVarArgs()
Of the methods, few are actually truly unique to that class type. Those would be the following methods

java.lang.reflect.Constructor
public T newInstance(Object ... initargs)
java.lang.reflect.Method
public Object getDefaultValue()
public Object invoke(Object obj, Object... args)
public Class getReturnType()
public boolean isBridge()
public Type getGenericReturnType()
A far smaller number, especially for Constructor. The remaining methods shared, but not accounted for in any superclass or interface, are:

Identical
public Annotation[][] getParameterAnnotations()
public Class[] getExceptionTypes()
public Class[] getParameterTypes()
public String toGenericString()
public Type[] getGenericExceptionTypes()
public Type[] getGenericParameterTypes()
public boolean isVarArgs()
These methods are just begging for an interface. Perhaps ParameterizedMember would be a good name?

Granted most Java development doesn't involve the reflection api, but those of us that do use it would really appreciate being thrown a bone. Especially with the growing amount of code and APIs that involve annotations. An interface similar to AnnotatedElement that can contain this critical getParameterAnnotations method would just be wonderful.

I'm quite certain there must have been some kind of debate. Likely one that ended in, "it's not really that important." Would love to hear from anyone involved.

I personally can't think of any downside to allowing us developers who deal with the guts of supporting annotation based APIs to get a little polymorphism in this are of the reflection API.

A bottle of my favorite rum to whomever can get this into Java 7.

23 comments:

Michael Campbell said...

"intense purposes"? =)

David Blevins said...

@Michael Wow, looks like I've been saying that incorrectly for years. Thanks, Michael!

Gunnar Morling said...

Seems like your wish might become reality :)

--Gunnar

爸爸 x said...

20170619 junda
oakley sunglasses sale
cheap jerseys wholesale
burberry outlet sale
cheap ray ban sunglasses
adidas uk store
michael kors outlet clearance
cheap nba jerseys
true religion outlet
ray ban sunglasses
nike air max 90

Habib Malik said...

North East Post Office Result 2017
Chhattisgarh Post Office GDS Result 2017
Uttarakhand Post Office GDS Result 2017
Haryana Post Office GDS Result 2017
Tamil Nadu Post Office GDS Result 2017

eric yao said...

Coach Outlet ED Hardy Outlet Coach Outlet Store Online Kate Spade Outlet Cheap Jordans Coach Purses Coach Outlet Kate Spade Outlet Toms Outlet Louis Vuitton

Danish Ahmed said...

Thanks for sharing this article, now you can also check your Recuritment & Notification 2017-2018 by following below given links...

fci andhra pradesh watchman recuritment 2017

fci tamilnadu watchman recuritment 2017

xat notification 2018

jkbote polytechnic result 2017

friv 10 said...


gracias por la detallada información. Friv 2019 Gry Friv 2018 Juegos Friv 3 Gracias por compartir sus ideas con nosotros. Gry Friv 3 Jeux De Friv Gracias por vuestras reacciones a las transmisiones que os han hecho. Friv 2019 Juegos Friv 2019 Acogemos con agrado los comentarios de los lectores

tong vo said...

gathered useful information on this point . Thank you posting relative information and its now becoming easier to complete this assignment

I enjoyed over read your blog post. Your blog have nice information, I got good ideas from this amazing blog. I am always searching like this type blog post. I hope I will see again..

learn to fly 2 said...

very amazing, Good Job, Thank you for presenting a wide variety of information that is very interesting to see in this artikle

potaup

Scott Porter said...

I am just starting to learn programming and these stuff in here looks very complex and incomprehensible.

Scott Porter (concrete overlay)

Jhon Perker said...

free sunil sex free sunil sex free sunil sex free sunil sex free sunil sex free sunil sex free sunil sex free sunil sex free sunil sex free sunil sex free sunil sex

Unknown said...

just information we only provide information for those who need it cara menggugurkan kandungan
A. obat telat datang bulan
B. posisi berhubungan agar cepat hamil
C. makanan dan minuman agar cepat hamil
D. panduan agar cepat hamil
E. cara agar cepat hamil
F. cara agar cepat hamil setelah selesai haid
G. cara alami untuk segera mendapat kehamilan

pintrovrt said...

Hello my friends my self Mehak Aahuja 5'5" 24 year young An Independent call girl.
http://pintrovrt.com/
Jaipur Escorts
Ludhiana Escorts
Ahmedabad Escorts
Jaipur Escorts

Anamta Sen said...

Hello friends My self Aaruhi Nanda 5'5" 24 year young an Independent call girls with Agency.
Lucknow Escorts
Ahmedabad Escorts
Jaipur Escorts
Ludhiana Escorts
Lucknow Call Girls

Ritika Patel said...

http://www.ritikapatel.com/surat-escort-service/


I am Ritika Patel from Surat escorts. If you want to get chance for my escorts service in Surat than contact me now. Our call girls in Surat are availble full day and night escorts service in Surat.

celebritiesfun said...

Jaipur Escorts Service where we hope every young big boobs sexy models woman of providing the best sexy for your entertainment for use only personal dating then right choice about Enjoy of erotic entertainment with very hot Sexy call girls in Jaipur.
Jaipur Call Girls
Goa Escorts
Ahmedabad Escorts
Mumbai Escorts
Delhi Escorts
Jaipur Escorts

Unknown said...

Really great post, I simply unearthed your site and needed to say that I have truly appreciated perusing your blog entries.

ReactJS Online Training

rithisaiaanand said...

This looks absolutely perfect. All these tiny details are made with a lot of background knowledge. I like it a lot. That was a great message in my carrier, and It's wonderful commands like mind relaxes with understanding words of knowledge by information.
Sql server dba online training

Unknown said...

union bank balance check number

gowsalya said...

I am really very happy to find this particular site. I just wanted to say thank you for this huge read!! I absolutely enjoying every petite bit of it and I have you bookmarked to test out new substance you post.
msbi online training

Kiruthiprabha said...

Nice post. By reading your blog, i get inspired and this provides some useful information. Thank you for posting this exclusive post for our vision..
Oracle DBA Online Training

Bhanu sharma said...

I am frequent visitor of your website as i love to read out the articles posted on your website. At the same time i request to post some great article on MBBS Consultants in Chandigarhand similar as well. Thanks !!!