Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static instance of Generic class

 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • 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
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Please see my verifying program. It doesn't seems working according to statemet.
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You used "static int count" which is class variable. There is only one for Type2<T> class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic