🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #14536

Re: instantiating from a class name

#14536
From: David Graff
Date: Mon, 30 Aug 1999 00:00
63 lines
3089 bytes
This is a multi-part message in MIME format.
--------------90007441D2DB8E91BE568D09
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I'd try first spreading that out a bit

Class c = Class.forName("classname");
Inteface i = (Interface) c.newInstance();

Make sure that you have a public no-arg constructor, otherwise this will not
work and you will have to locate the parameters for the constructor and
other nasty sorts of things


Steve Grant wrote:

> I'd like to be able to build a JTree using models that are loaded by
> passing the model name.  The basic idea is to instantiate an instance
> variable of the interface that all the models implement in a separate
> class, and then use the interface methods to build the tree without ever
> knowing in advance which tree will be built. My problem is that I can't
> seem to use the (interface)Class.forname("classname").newInstance() and
> get anything other than null. The other complication is that the models
> take parameters but I think I could handle this with a separate
> interface function as opposed to through a constructor. My thought was
> that if I have trees which can take variable models it would good
> practice to make those trees pluggable. I would appreciate any help on
> how to use the forname/instanceof construction or if I 've got something
> wrong in how I'm conceving this. Thanks.

--
****************************************************************
David J. Graff                               IQXPERT
mailto:david.graff@iqxpert.com               Phone: (770) 953-1464
Direct: (770) 240-2289                       Fax: (770) 953-1574
****************************************************************


--------------90007441D2DB8E91BE568D09
Content-Type: text/x-vcard; charset=us-ascii;
 name="david.graff.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for David Graff
Content-Disposition: attachment;
 filename="david.graff.vcf"

begin:vcard 
n:Graff;David
tel;fax:(770) 953-1574
tel;work:(770) 240-2289
x-mozilla-html:TRUE
url:http://www.iqxpert.com
org:IQXPERT
version:2.1
email;internet:david.graff@iqxpert.com
title:Software Engineer
adr;quoted-printable:;;5500 Interstate North Parkway=0D=0ASuite 507;Atlanta;GA;30328;USA
x-mozilla-cpt:;1776
fn:David Graff
end:vcard

--------------90007441D2DB8E91BE568D09--
Technical Details
Message-ID: <37CAB1F6.F9738FB7@iqxpert.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <37CA93AC.C3877419@well.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,62b39a9dceca75bd
X-Google-Attributes: gid111d45,public
X-Google-Thread: f74b3,62b39a9dceca75bd
X-Google-Attributes: gidf74b3,public
From: David Graff <david.graff@iqxpert.com>
Subject: Re: instantiating from a class name
Date: 1999/08/30
Message-ID: <37CAB1F6.F9738FB7@iqxpert.com>
X-Deja-AN: 518925941
References: <37CA93AC.C3877419@well.com>
To: Steve Grant <sgrant@well.com>
X-Accept-Language: en
Content-Type: multipart/mixed; boundary="------------90007441D2DB8E91BE568D09"
Organization: IQXPERT
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language,borland.public.jbuilder.java.swing