• 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

Generic denifition T super Number

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class GenericClassDefinition<T super Number> {
public static void main(String...strings)
{

}

}


T extends Number :- Compiles fine
T super Number :- Giving error.

Why compiler is not allowed me to declare 'T' Type as T super Number?
I searched for similar topic here, not able to find
Can anyone provide me link if it is already discussed here?
Otherwise can anyone explain me it?

rami
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ram,

Lower bound for type parameters are not allowed. Replace super by extends it will work.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this...

http://www.angelikalanger.com/GenericsFAQ/FAQSections/TypeParameters.html#Why%20is%20there%20no%20lower%20bound%20for%20type%20parameters?

Basically the compiler doesn't allow it because it's pointless (although I thought java had many instances where pointless and optional/flexible syntax go hand in hand); it implies an "unlimited" range!
[ June 12, 2008: Message edited by: Frank Zito ]
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ram,

I thought of something, for why a compiler doesn't
allow a <T super someType>... Its kind of vague though..

Considering,




Here rental is a template... "Foreseeing" that the code would be just the same for a CarRental or a BikeRental, the programmer would've decided to go for a template like this ( so that it saves a lot of typing...)

If he wanted to allow all types of cars to use the same template he would say that by class Rental<T extends Car>... Thats all he might have wanted to do...

i.e while creating a format, a template, he does so only seeing the "type" or the "subtype" to which it can be applied to, so disallowing the superType looks quite logical...
 
reply
    Bookmark Topic Watch Topic
  • New Topic