constructor loading it's object from a file

From: Murat Tasan (tasan_at_eecs.cwru.edu)
Date: 12/04/03


Date: Wed, 3 Dec 2003 18:03:35 -0500

i'd like to have a constructor that loads an object from disk and returns
it... kinda like:

class MyClass
{
        MyClass(File f)
        {
                ObjectInputStream s = new ObjectInputStream(new
FileInputStream(f));
                this = (MyClass)s.readObject();
        }
}

now i know you cannot do this because this in the constructor is a final
variable...

is there trick that i don't know of that can do this?

p.s., before i get the typical responses... i already am using a static
factory method to accomplish the same thing... i'm just looking to make it
even easier to use my classes.

thanks for any help,

murat

-- 
Murat Tasan
mxt6@po.cwru.edu
tasan@eecs.cwru.edu
murat.tasan@cwru.edu
http://genomics.cwru.edu


Relevant Pages

  • Re: constructor loading its object from a file
    ... > i'd like to have a constructor that loads an object from disk and returns ... kinda like: ... > class MyClass ... > factory method to accomplish the same thing... ...
    (comp.lang.java)
  • Trouble with non-default constructors
    ... I have a class that needs a non-default constructor, ... class MyClass ... int Value; ... But if I try to compile my compilers complains there's no default ...
    (alt.comp.lang.learn.c-cpp)
  • Re: How to share data?
    ... > int getdata; ... Why is readdata() public? ... Your constructor copies the values ...
    (comp.programming)
  • Re: Object instantiation in C#
    ... >> I have a class MyClass that throws exceptions. ... > When an UNCAUGHT exception occurs in a constructor, ... > pointing to whatever it was pointing to before. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Trouble with non-default constructors
    ... > I have a class that needs a non-default constructor, ... > class MyClass ... > void GetValue{return Value); ... > But if I try to compile my compilers complains there's no default ...
    (alt.comp.lang.learn.c-cpp)