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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Himai Minh

some problems in generics

Ranch Hand
Posts: 658
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
i have almost completed the generic chapter and these are some doubts in my mind. These doubts will help me to finish this chapter(which i decided to complete by today)

1. if List(?) is a reifiable then why List(? extends Object) is not a reifiable type ?? (even though Type Erasure will convert both into List(Object)
according to defination reifiable is the type which is completely represented at runtime i.e. no useful information is removed(type information)

2. what is the difference between these two generics method
one difference is that first one is the class method, i.e no class instance is needed to call that method. Is there any other difference in the working of these method ?

3. why static generic method cannot use Type parameter defined by class
my reason for this: since static method can be called even if there is no instance and if there is no instance of generic class, the type parameter are unknown... so they are not allowed

4. why Type parameter cant be static
my reason :a) since static variable are the class variable and get there value at compile time, but Type parameter are unknown at compiler this is not allowed
b) since static varibale are class variable and the original variable itself is shared among all the instances(not copy), so for generics it will be difficult for the compiler to predict the type of variable if there are multiple instance ie. Gen<Integer> g=new Gen<>(12); Gen<Stringr> g=new Gen<>("hello");
so now it is impossible for compiler to know about the type of the variable obj .

it is valid but,
is not a valid class..why super is not allowed here ??

6. how can i see the type erased code by the compler?? i tried
javap Gen

but is not working. It simply showing T type for the unbounded type, should show Object

Thank you
author & internet detective
Posts: 41250
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Closing because duplicate of
No holds barred. And no bars holed. Except this tiny ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic