File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes static instance of Generic class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "static instance of Generic class" Watch "static instance of Generic class" New topic
Author

static instance of Generic class

Amirr Rafique
Ranch Hand

Joined: Nov 14, 2005
Posts: 324
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


"Know where to find the solution and how to use it - that's the secret of success."
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
Regarding information you find in various sources, in the words of Ronald Reagan Trust, but verify.
[ May 31, 2006: Message edited by: Garrett Rowe ]

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Amirr Rafique
Ranch Hand

Joined: Nov 14, 2005
Posts: 324
Please see my verifying program. It doesn't seems working according to statemet.
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
You used "static int count" which is class variable. There is only one for Type2<T> class.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: static instance of Generic class