2013/5/10 Konstantin Preißer <verlag.preis...@t-online.de>: > Hi all, > > I apologize for being completely off-topic (this question has nothing to do > with Tomcat), but I thought there may be some guys here that are experts in > class loading and are able to answer my question. > > > You probably know the method java.lang.Class.forName(String name) which > returns a class object from the given name. The JavaDoc (Java 7) of this > method says: > > Returns the Class object associated with the class or interface with > the given string name. Invoking this method is equivalent to: > Class.forName(className, true, currentLoader) > where currentLoader denotes the defining class loader of the current > class. > > While this description may be a bit ambiguous about what "current class" > means here, the JavaDoc of Class.forName(String name, boolean initialize, > ClassLoader loader) makes it clearer by stating: > > For example, in an instance method the expression: > Class.forName("Foo") > is equivalent to: > Class.forName("Foo", true, this.getClass().getClassLoader()) > > > So, shouldn't this mean that I get the same result/behavior when writing this > code: > > public void doSomething() throws ClassNotFoundException { > Class<?> clazz = Class.forName("foo.Bar"); > // do something... > } > > Instead of this one: > > public void doSomething() throws ClassNotFoundException { > Class<?> clazz = Class.forName("foo.Bar", true, > this.getClass().getClassLoader()); > // do something... > } > > or did I misunderstand something? >
Yes, the same. BTW, Oracle JDKs come with source code for their public classes, On Windows that is %JAVA_HOME%/src.zip. Do you have such file? Best regards, Konstantin Kolinko --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org