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.

27 comments:

Michael Campbell said...

"intense purposes"? =)

David Blevins said...

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

Unknown said...

Seems like your wish might become reality :)

--Gunnar

Unknown 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

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

nicova 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..

alicetaylor123 said...

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

potaup

Unknown said...

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

Scott Porter (concrete overlay)

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.

sasitamil 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

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

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

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

Unknown said...

If you would like to book an escort like Russian Escorts in Haridwar for an upcoming time, you can use our mail reservation type where you can specify a substitute woman should your perfect option not be available. You will need to provide us with your real name on thereservation type, but be confident we are very distinct and will keep your private information private and protected. Check our other Services...
Bengali Call Girls in Kolkata
Call Girls in Ahmedabad
Call Girls in Faridabad
Call Girls in Goa
Call Girls in Gurgaon
Escorts in Faridabad

El Awal said...

شركة مكافحة حشرات ببريدة
شركة مكافحة حشرات بالبكيرية
شركة مكافحة حشرات بالدوادمي
شركة رش مبيدات بالخرج
شركة رش دفان بالقصيم
شركة مكافحة حشرات بالقصيم
شركة مكافحة حشرات بعنيزة

bandarq228 said...

dapatkan penghasilan tambahan dengan mudah hanya dengan mengguanakan gadget anda dengan bermain di bandar togel online yang aman dan terpercaya masbrotogel
daftarkan diri anda sekarang juga dan raih bonus hingga ratusan juta hanya di http://masbrotogel.com/

Uniqueplayboy said...

Hi Guys, I’m Sameera Rai gorgeous model in Jaipur. I like to enjoy a modern lifestyle with my lovers. Many people approach me to have fun with my curvy figure. I just love to be their companion and provide them my exceptional love-making. Being one of the demanding Jaipur escorts, uniqueplayboy have been serving me by providing all meetings. The amazing erotic experience that you can get with me would be remarkable. I ensure to serve me by giving me 100% satisfactory services. If you want some erotic desires, simply go to Dating Services in India and fulfill your extreme sensuous desires.

chennaidesire said...

Delhi escorts are educated along with experience and we are providing you with the best call girl for your satisfaction .

Muskan Patel said...

You can even agreement the prostitutes to stay with you as your companion when you go on a long journey alone. These young ladies are continually organized to be with you and make you battled in each possible manner.

Surat Escorts
Surat Escorts Service
Daman Escorts
Vapi Escorts
Diu Escorts
Dofollow link

nituroy.com said...

Explore the profiles of guwahati escorts, guwahati call girls, call girls in guwahati and
escorts in guwahati for female companionship in top rated hotels. Get affordable
escort services in guwahati hotels now.Nitu Roy is a popular and
trusted name in the field of call girl service.
Guwahati escort service
Escort service in Guwahati

Hotelescortservices.com said...

Very nicely and well written article
Call girls in Jammu

India Web Cares said...

Does anybody else will tackle your Website Designing Company In India? If you've located an agency that offers you superb outcomes at a reasonable price, after that you shouldn't enable others to mess up your website. It is feasible to call them with other demands and inquire on the Website Designing Company In India work they execute however there's no factor to separate the task between two firms. Forum Submission sites List

nide said...

web link description look at these guys discover this info here more helpful hints Extra resources

Anonymous said...

x8o81w3a69 f9f04v6n33 j0j56s3w54 q1w05q7n39 n3m91l0a54 a9f47a4s79

Priya said...

wonderful blog. It's very interesting to read...

AWS Training course at Edukators in Coimbatore