Hi,
I tried to use an interface to enforce the plugin developers to implement the function "initialize(Composite parent, int style)".
Interface:
a Test-Plugin is this:
Now, the main application, which intends to load the plugin, needs to cast the successfully loaded class (fqcn). I wanted to do this with an interface. From what I've read, this is recommendable and good practice.
Class loading passes fine (no exceptions). Then the casting with IPlugin fails with a java.lang.ClassCastException. No additional error text/hints. Why does that casting request fail?
Thanks heaps for any hints!
I tried to use an interface to enforce the plugin developers to implement the function "initialize(Composite parent, int style)".
Interface:
Code:
import org.eclipse.swt.widgets.Composite;
interface IPlugin {
void initialize(Composite parent, int style);
}
a Test-Plugin is this:
Code:
public class Loader extends Object implements IPlugin{
//a nullary constructor. mandatory for casting!
public Loader() {
}
public void initialize(Composite parent, int style){
FlashCardsPlugin fcp = new FlashCardsPlugin(parent, style);
}
}
Now, the main application, which intends to load the plugin, needs to cast the successfully loaded class (fqcn). I wanted to do this with an interface. From what I've read, this is recommendable and good practice.
Code:
...
LocalClassLoader lcl=new LocalClassLoader(jar);
String strClass = "com.brayan.projects.icda.apps.flashcards.Loader";
Class<?> c = lcl.loadClass(strClass);
[red]IPlugin plugin = (IPlugin)c.newInstance();[/red]
Class loading passes fine (no exceptions). Then the casting with IPlugin fails with a java.lang.ClassCastException. No additional error text/hints. Why does that casting request fail?
Thanks heaps for any hints!