commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Juozas Baliuka" <bali...@centras.lt>
Subject Re: [lang] reflect - Class.forName
Date Sun, 24 Nov 2002 12:31:11 GMT

It is no good way to "discover" class loader,
but I prefer to try the most "specific" class loader first, like
java.beans.Introspector doe's to find "BeanInfo".
Thread context class loader is the "last".

javac generates code like this to implement "MyClass.class" :

 static Class class$(String name){
   try{
       return Class.forName(name);
   }catch( ClassNotFoundException cnfe ){
      throw new ClassNotFoundError(cnfe.getMessage());
  }
}

 static Class $MyClass = class$("MyClass");

I think this class loader must be used by library the first too, if possible
.


----- Original Message -----
From: "Max Rydahl Andersen" <max@eos.dk>
To: "Jakarta Commons Developers List" <commons-dev@jakarta.apache.org>
Sent: Sunday, November 24, 2002 11:10 AM
Subject: Re: [lang] reflect - Class.forName


> hmm - I just came to think of another "issue".
>
> To have correct classloading semantics the class that is used to load
> classes dynamically (e.g. RequestUtils) needs to have been loaded by the
> same classloader as the caller of the function ......that actually means
it
> cannot be generalized to be a general function in a general library that
is
> just loaded by some "global" or "third-party" classloader...This should
not
> stop one from using the proposed load semantics, it should just be
> documented that that is the case (no one newer said that java classloading
> should be easy :)
>
> /max
>
> ----- Original Message -----
> From: "Steve Downey" <steve.downey@netfolio.com>
> To: "Jakarta Commons Developers List" <commons-dev@jakarta.apache.org>
> Sent: Sunday, November 24, 2002 6:46 AM
> Subject: Re: [lang] reflect - Class.forName
>
>
> +1, as the reasoning seems quite sane.
>
>
> On Saturday 23 November 2002 09:17 pm, Henri Yandell wrote:
> > I've not really been paying attention to the reflect stuff, and had
missed
> > a question about it in a blog I usually read:
> >
> > http://radio.weblogs.com/0112098/2002/09/24.html#a114
> >
> > Rather than using:
> >
> > Class theClass = Class.forName( className );
> >
> > in reflect.ReflectionUtils, James suggests we should use:
> >
> > ****
> > Class theClass = null;
> >
> > try {
> >  theClass = Thread.currentThread().getContextClassLoader().loadClass(
> > className );
> > } catch (ClassNotFoundException e) {
> >  theClass = getClass().getClassLoader().loadClass( className );
> > }
> > ****
> >
> > as "Class.forName is evil".
> >
> > Any views on this??
> >
> > Hen
>
>
> --
> To unsubscribe, e-mail:
> <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:commons-dev-help@jakarta.apache.org>
>
>
>
>
> --
> To unsubscribe, e-mail:
<mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:commons-dev-help@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message