ebooksgratis.com

See also ebooksgratis.com: no banners, no cookies, totally FREE.

CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
Privacy Policy Cookie Policy Terms and Conditions
Talk:Generics in Java - Wikipedia, the free encyclopedia

Talk:Generics in Java

From Wikipedia, the free encyclopedia

Contents

[edit] Reflection example not correct

I removed the following text, as it isn't correct:

It is possible to work around this limitation to some extent by using Java's reflection mechanisms. If an instance of class T is available, one can obtain from that object the Class object corresponding to T and use java.lang.reflect.Array.newInstance to create the array.

Let's say I have toArray(List<T> list) with at least one element. I call this using a List&ltNumber&gt containing Integers and Floats. Array.newInstance() using my first element of my list (which an instance of class Number) I end up with an array of type Integer[]. When I try to add a Float to the array, my program will fail with an error.

Now, it is possible if I pass in a Class<T> as in toArray(List<T> list, Class<T> clazz). Calling Array.newInstance(clazz, list.length()) will work just fine. However, I don't think it's worth mentioning this in the actual article. —Matthew0028 07:50, 11 December 2006 (UTC)

[edit] Anti-Java bias

This article only tells what the problems are with Java generics. It doesn't even tell you how to use any of the generic features, like the For-next loop or autoboxing. —The preceding unsigned comment was added by Ed Poor (talkcontribs) 22:30, 7 February 2007 (UTC).

Indeed. It doesn't even define Generics. The first sentence talks about when they were added to the language, and the second goes right into comparison with C++. This article needs work. --King Mir 01:52, 13 February 2007 (UTC)
This article used to be part of the generic programming page (but you know that already), which provided a little more context on the subject. I agree it should at least mention how it can help with type safety (even if only to a degree) and readability (same footnote), and can prevent the need for casts. (Note that foreach and autoboxing don't really require generics, they were in the C# language before it introduced generics.) Perhaps some examples that show the good points would be nice too. - Chip Zero 15:38, 13 February 2007 (UTC)

[edit] Anti-Java bias Updated

Removed the Anti-Java Content, Added viable examples, Corrected Incorrect Example.

This is not a facility to compare Java to other languages; If a comparison is useful, it has every reason to be here.

Please take the time to remove negative/spiteful content when ever possible.

Thank you =)

[edit] Feb 2008 edits

I tried to improve content of this article. We certainly have to start with relevant to this subject Java language specifications - then to go down to examples. I do not see any reason for autoboxing/unboxing section here - it has nothing to do with generics. Also, nested generics 'explained' here by an example - are simply ugly.--Stagalj (talk) 00:08, 13 February 2008 (UTC)


aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -