• 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

static instance of Generic class

 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As per below lines from Ivor Hoton's book

Even though all types produced from a given generic type share the same run-time type, they still
have their own independent static fields. For example, suppose you were to add a static field�
count, say� of type int to the LinkedList<> type definition to record the number of objects created.
You�d then add a statement to the constructor to increment count each time it was called. Each
type instance, such as LinkedList<String> or LinkedList<Point>, would have its own copy of count,
so the static count member of the LinkedList<String> type would correctly reflect the number of
times the LinkedList<String> constructor had been called.



Please explain


Thanks
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Regarding information you find in various sources, in the words of Ronald Reagan Trust, but verify.
[ May 31, 2006: Message edited by: Garrett Rowe ]
 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please see my verifying program. It doesn't seems working according to statemet.
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You used "static int count" which is class variable. There is only one for Type2<T> class.
 
reply
    Bookmark Topic Watch Topic
  • New Topic