On Apr 8, 4:13 pm, "Mike Schilling" <mscottschill...@hotmail.com>
wrote:
> > Do not know if this is possible or not:
>
[quoted text clipped - 32 lines]
> detail, but, basically if all of the original fields and methods are still
> present with the same names and types, you're OK.
What I mean is:
Say A is a GUI application, it has a open file browser button. The
user can use the open file browser to locate a .jar file, which
contains the code for B (say, Tom has his one Tom_B.jar, Kevin has his
Kevin_B.jar, etc). And all these Tom_B.jar, Kevin_B.jar etc. have the
same functions (interface). Then A can call this interface to do what
it wants to do.
These Tom_B.jar, Kevin_B.jar etc are not known in advance. We only
know they all follow the same interfaces and have the same function
names.
A good example I can think of is that the class B implement the sort
function. So it is left out side A so that different people can write
them own sort, which take the same input and have the same output
format, also same function name etc (interface). But different people
can code it using different algorithms. And application A does not
know that, also does not care it. All it does is at run time after it
starts up, "hot swap" the sort from whatever .jar file the user
provides. These .jar file are not known in advance.
Mark Space - 09 Apr 2008 01:12 GMT
> What I mean is:
>
> Say A is a GUI application, it has a open file browser button. The
> user can use the open file browser to locate a .jar file, which
> contains the code for B (say, Tom has his one Tom_B.jar, Kevin has his
> Kevin_B.jar, etc). And all these Tom_B.jar, Kevin_B.jar etc. have the
I think Arne's post covers this. See his post above.
When the user selects a .jar file, dump your existing classloader (that
you made before) and make a new one, then load the .jar file with the
classloader.
I'm sure it will be a fair amount of work, but the outline of what to do
makes sense.
Lew - 09 Apr 2008 01:23 GMT
>> What I mean is:
>>
[quoted text clipped - 11 lines]
> I'm sure it will be a fair amount of work, but the outline of what to do
> makes sense.
Also, the debugger interface lets the JVM hotswap a class for a new (or old)
implementation without restarting the JVM.

Signature
Lew
Mike Schilling - 09 Apr 2008 01:56 GMT
> On Apr 8, 4:13 pm, "Mike Schilling" <mscottschill...@hotmail.com>
> wrote:
[quoted text clipped - 63 lines]
> starts up, "hot swap" the sort from whatever .jar file the user
> provides. These .jar file are not known in advance.
Then the answer Arne game is correct, but it's still easiest to have the
loaded class implement an interface (call it BInt) rather than replace a
concrete class. When you're given the jar file, create a classloader that
reads from Kevin_B.jar and has the classloader from which A was loaded as a
parent. You can get the class object from the new class loader, and use it
to instantiate the object, which you can cast to BInt, and then call
whatever methods you like on it. This gets more difficult if you don't know
a type that B implements (or extends); then you can only treat the instance
as an Object, and need to use reflection to make it do anything.