[687] in java-interest

home help back first fref pref prev next nref lref last post

java-interest-digest V1 #83

daemon@ATHENA.MIT.EDU (java-interest@java.sun.com@cs.prus)
Thu Jul 13 09:07:04 1995

From: java-interest@java.sun.com@cs.prusec.com
To: crusher.cs.prusec.com!java.sun.com!java-interest@java
Date: Thu, 13 Jul 95 11:55:03 GMT
Not-Delivered-To: due to 11  Transfer Failure
     ORIGINAL MESSAGE ATTACHED
     (rmail: Error # 22 'Surrogate command failed', rc = 1)
En-Route-To: !walter-ws.cs.prusec.com.#walter.hjelmar!walterh 
     ======= Surrogate command =======
     :smtpqer cs.prusec.com!java.sun.com!java-interest walter-ws.cs.prusec.com.#walter.hjelmar walterh 
     ==== Start of stdout ===
     ==== Start of stderr ===
     :UX:smtpqer: INFO: unknown host <walter-ws.cs.prusec.com.#walter.hjelmar>
En-Route-To: !walter-ws.cs.prusec.com.#walter.hjelmar!walterh 

From smtp Thu Jul 13 07:55 EDT 1995
Received: from cs.prusec.com by prusec.prusec.com; Thu, 13 Jul 95 07:55 EDT
Received: from prufsg.cs.prusec.com by crusher.cs.prusec.com (AIX 3.2/UCB 5.64/4.03)
          id AA09999; Thu, 13 Jul 1995 07:56:09 -0400
Received: from java.sun.com by prusec.prusec.com; Thu, 13 Jul 95 07:54 EDT
Received: (from majordom@localhost) by java (8.6.12/8.6.12) id XAA14094 for java-interest-digest-outgoing; Wed, 12 Jul 1995 23:30:08 -0700
From: java-interest@java.sun.com@cs.prusec.com
Date: Wed, 12 Jul 1995 23:30:08 -0700
Message-Id: <199507130630.XAA14094@java>
>From: owner-java-interest-digest@java.sun.com
To: java-interest-digest@java.sun.com
Subject: java-interest-digest V1 #83
Reply-To: java-interest@java.sun.com@cs.prusec.com
Errors-To: owner-java-interest-digest@java.sun.com@cs.prusec.com
Content-Length: 2057
Content-Type: text
Precedence: bulk
X-Info: To unsubscribe, send 'unsubscribe' to java-interest-digest-request@java.sun.com

java-interest-digest       Thursday, 13 July 1995       Volume 01 : Number 083

In this issue:

 	Re: Class.newInstance() question
 	Re: Class.newInstance() question

----------------------------------------------------------------------

From: cmcmanis@scndprsn.Eng.Sun.COM (Chuck McManis)
Date: Wed, 12 Jul 1995 22:43:14 -0700
Subject: Re: Class.newInstance() question

The best way to do this is to define an interface that objects you want
to create this way can use. Thus you would define:

public interface Loadable {
    public Object make(String parameter);
}

And then in objects you were instantiating you would use:

    Class foo = Class.forName("MyCustomClass");
    return ((Loadable)(foo.newInstance()).make("Some parameter"));

Now you could also protect it like this:

    Object x;
 
    try {
	x = (Loadable) (foo.newInstance()).make("Some Parameter");
    } catch (Exception e) {
	// didn't work , probably doesn't implement loadable
	x = null;
    }
    return (x);

So if the object you were instantiating couldn't be made loadable it wouldn't.

You would write a loadable object like so:

class Bletch implements Loadable {
    /** MUST have a null constructor if you want newInstance to work */
    public Bletch(){
    }

    public Bletch(String xyzzy) {
    }

    public Bletch make(String fooey) {
	return new Bletch(fooey);
    }
}


A bit of overhead but it gets the job done. 

- --Chuck

------------------------------

From: jpayne@starwave.com (Jonathan Payne)
Date: Wed, 12 Jul 1995 23:27:21 -0700
Subject: Re: Class.newInstance() question

You should just create your class in the normal way

	YourClass foo = new ("YourClass");

and then call a well-defined method, perhaps initialize(...) to
actually initialize it as if you had passed the args in the
constructor.

Oh, the above example should contain a cast from the new expression to
(YourClass), since it's not known at compile time what type new will
return.

------------------------------

End of java-interest-digest V1 #83
**********************************


-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post