• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why is Java Generic called generic?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Small confusion in understanding the name Java 'Generic'


In the code snippet above, myIntList can be casted to any type(Integer,Double ,String..) which means that variable myIntList though not TYPESAFE is a GENERIC variable as it can be casted to any required type . Now consider the following code:

The variable myIntList is being RESTRICTED to be of type Integer. Then why is the term GENERIC coined ? Am I overlooking an important idea behind this?

Thanks in advance.




 
Master Rancher
Posts: 4830
74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote about this back here. See my response after Janeice asks "Why do they call it 'generics' when it's all about being more 'specific'?" It's part of a much larger conversation, but I think it also stands on its own.
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The term is inherited from existing techniques, started in 1983 and made quite popular by C++. Source: http://en.wikipedia.org/wiki/Generic_programming
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:The term is inherited from existing techniques, started in 1983 and made quite popular by C++. Source: http://en.wikipedia.org/wiki/Generic_programming


No way; Ada had generics in the late 70's.

<offtopic>Ada had some really nice features.</offtopic>
 
Rob Spoor
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then I suggest you modify the Wiki article, because it clearly states

This approach, pioneered by Ada in 1983

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It also states "Ada has had generics since it was first designed in 1977–1980", and to be honest, I don't remember it *not* being in Ada, but that was a long time ago, and I was little.
 
Rob Spoor
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That'll teach me to read beyond the first 5 lines...
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bah; where's the adventure in that?
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Yeddu Prabhakara Rao wrote:is a GENERIC variable as it can be casted to any required type .



The term generic variable doesn't exist in Java.

The meaning you've assigned to it is arbitrary.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic