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.

28 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 !!!

pintrovrt said...

Welcome to pintrovrt (SAVITA), feel free to review our gallery of sexy Ahmedabad Girls below. We offer a beautiful model escort the way you really want! and they will make your stay truly magical!. Everyone is familiar with the expression. This experience is waiting for you. For the perfect companion! visit us anytime @
Ahmedabad Escorts | Andheri Escorts | Jaipur Escorts | Zirakpur Escorts | Goa Escorts | Chandigarh Call Girls | Chandigarh Escorts

Carpet Thailand 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 Carpet in Thailand and similar as well. Thanks !!!

sweetheart said...

I Am Thankful To You For Create Such Kind Of Informative Website. Really It Is Useful According Your Current Topic. I Suggest To Keep This Continue For Those People, Who Are Looking For Such Kind Of Niche. After See Your Niche I Have Recommended Your Website With My Friends Also.
My name is Arpita Jain. I run my independent Mumbai Escorts Service. I am an independent Mumbai escort girl. My service charge is low according the current market price. My service is super, because I know very well the personal requirement of my each customer. I am comfortable to provide my Mumbai Escorts Service at your home or in Hotel. Visit- http://www.arpitajain.org/ Call- +91 9OO4458359
Visit The Links Below And Have A Look At My Various Mumbai Escort Services-


Mumbai Escorts Service

Juhu Escorts
Mumbai Call Girls
Escort Service In Mumbai
Andheri Escorts
Bandra Escorts

rosemary said...

I Saw Your Website Carefully. Thanks For Create Such Kind of Informative Website. Your All Content Is Relevant To Your Subject. I Say Keep It Continue, Because Your Website And Subject Is Meaningful For The Users. I Have Recommended Your Website With My Friends Also.
I Am Ritu Sharma. I Deal In Private Escorts In Mumbai. I Am Very Hot And Sexy. I Have Five Years’ Experience In My Profession. That’s why I Understand the Each Personal Needs of My Every Client. My Service Charge Is Low And Service Is Super. You Can Avail My Private VIP Service At Your Home Or In Hotel. I Am Comfortable To Provide Service In Local And Outside Also. To Book My Service Call +91- 9OO4OO9481
Visit http://www.escortservicemumbai.net/private-escorts-in-mumbai/

Visit The Links Below And Have A Look At My Various Mumbai Escort Services-
Mumbai Escorts
Mumbai Call Girls
Juhu Escorts
Andheri Escorts
Bandra Escorts
Private Escorts In Mumbai
Mumbai Prostitutes






lovepriya1 said...

Thanks For Create Such Kind Of Informative Website. All Content Is Relevant To Your Subject. Keep It Continue, Because Your Website And Subject Is Meaningful For The Users. After See Your Niche I Have Recommended Your Website With My Friends Also.
My Name Is Priya Singh. I Run My Own Mumbai Independent EscortsI Am An Independent Mumbai Escort Girl. I Am Beautiful And Hot. My Service Charge Is Low And Service Is Super. Being Professional I Have Seven Years’ Experience As An Escort Girl. So I Understand And Feel The Real Needs And Requirement Of My Each Client. According The Convenience You Can Avail My VIP Escort Service At Your Home Or In Hotel Also. To Book My VIP Mumbai Escort Service Call +91 9987215552.
Visit- http://www.escortagencyinmumbai.com/mumbai-independent-escorts/
Visit The Links Below And Have A Look At My Various Mumbai Escort Services-
Mumbai Escorts
Mumbai Independent Escorts
Prostitutes Near Me Number
Mumbai Escorts In Khar.
Mumbai Escorts In Borivali.
Mumbai Escorts in Andheri
Escort Service in Gore Goan
Mumbai Escorts in Juhu
Bandra Escorts