L
laviofer
So here is what I am after:
I want to have a generic class MyClass<T> that holds a data member
ArrayList<T> m_TList
Now, suppose I have a method that reads a file, and has to fill in the
list. The file is a list of strings, and I want to have a registry
class that knows how to turn a string into a T object. T is
"Identifiable" - that is, each object has a unique String ID. I want
the T class to be able to return its (static) Registry object so to
have something like:
public class MyClass<T>
{
public void readFile(String filename)
{
// open file
// get registry of T
Registry<T> registryOfT = ...
// for each line of file
// read String ID
T newObject = registryOfT.getObject( ID );
m_TList.add( newObject )
}
}
The idea is that T can be a person with a social security number ID,
or a part with a unique identifier.
Any ideas?
Thanks, Ofer.
I want to have a generic class MyClass<T> that holds a data member
ArrayList<T> m_TList
Now, suppose I have a method that reads a file, and has to fill in the
list. The file is a list of strings, and I want to have a registry
class that knows how to turn a string into a T object. T is
"Identifiable" - that is, each object has a unique String ID. I want
the T class to be able to return its (static) Registry object so to
have something like:
public class MyClass<T>
{
public void readFile(String filename)
{
// open file
// get registry of T
Registry<T> registryOfT = ...
// for each line of file
// read String ID
T newObject = registryOfT.getObject( ID );
m_TList.add( newObject )
}
}
The idea is that T can be a person with a social security number ID,
or a part with a unique identifier.
Any ideas?
Thanks, Ofer.