Well, it is probably quite simple, but I can't seem to make it work. The thing is that I would like to have a reference to the object from within the class that implements the object. I have got a class 'Users' in which I have got a method 'load'. I would like this method to initialize the object from a file, like this...
Code:
public void load(String filename)
{
File f = new File(filename);
if(f.exists())
{
ObjectInputStream ois = null;
try
{
ois = new ObjectInputStream(new FileInputStream(filename));
this = (Users)ois.readObject();
ois.close();
}
catch(Exception e)
{
System.err.println("!-> error: " + e);
}
}
}
In the above code I have assigned the result from readObject to 'this', which would be the intuitive way to do this, however it does not seem to work.
I have tried to make a private instance of the class and then assigning 'this' to the new instance, but then I can't use the methods of the class, which I have extended, in this...
Code:
public class Users extends Hashtable implements Serializable
It seems to be an evil circle! A work-around would be to return an object of type 'Users' from the load method and then assigning it when calling load, but I do not like this solution, since I then have to make an instance of that class and then assign it to another!
Thanks!
Jacob.