Can a class be loaded twice?

  • Thread starter MARTIN Herve \(EXT\)
  • Start date
M

MARTIN Herve \(EXT\)

Hi,

I've created a compiler integrated within a graphical application.
The user writes a script in the language of the application, compiles and
then execute it.

The compilation creates new Java classes which then are loaded into the
application to be executed.

Up to now, the compiler never generates twice a Java class with the same
name, so the same script can be compiled twice, and the class created can be
loaded with non name conflict.

But can't the same class be loaded twice with the same name, provided that
no object of this class is used??
 
S

Skippy

I've created a compiler integrated within a graphical application.
The user writes a script in the language of the application, compiles and
then execute it.

The compilation creates new Java classes which then are loaded into the
application to be executed.

Up to now, the compiler never generates twice a Java class with the same
name, so the same script can be compiled twice, and the class created can be
loaded with non name conflict.

But can't the same class be loaded twice with the same name, provided that
no object of this class is used??

If you generate a class with the same name, all *new* objects will be using
the new version, the old versions will keep using the old class.
 
A

Adam Maass

MARTIN Herve (EXT) said:
Hi,

I've created a compiler integrated within a graphical application.
The user writes a script in the language of the application, compiles and
then execute it.

The compilation creates new Java classes which then are loaded into the
application to be executed.

Up to now, the compiler never generates twice a Java class with the same
name, so the same script can be compiled twice, and the class created can be
loaded with non name conflict.

But can't the same class be loaded twice with the same name, provided that
no object of this class is used??

The same class can be loaded arbitrarily many times -- under different
classloaders.

-- Adam Maass
 
L

Larry A Barowski

MARTIN Herve \(EXT\) said:
...

But can't the same class be loaded twice with the same name, provided that
no object of this class is used??

If you use a new URLClassLoader to load the class, everything
will work fine as long as the location of the classes is NOT on
the classpath. Instances of an old and new class with the same
name can coexist with no problem.

-Larry Barowski
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top