M
Moiristo
A short question about forName:
I have an interface called 'GeometryPainter' and a subclass that
implements it, which is called 'DefaultGeometryPainter'. I'm
instantiating the DefaultGeometryPainter as following (Java5):
Class painter = Class.forName(lpainterClass);
GeometryPainter gm = GeometryPainter.class.cast(painter);
It finds the class, because I don't get a ClassNotFoundException, but I
cannot cast it to GeometryPainter (it throws a ClassCastException). Can
someone tell me why? What should I do?
I have an interface called 'GeometryPainter' and a subclass that
implements it, which is called 'DefaultGeometryPainter'. I'm
instantiating the DefaultGeometryPainter as following (Java5):
Class painter = Class.forName(lpainterClass);
GeometryPainter gm = GeometryPainter.class.cast(painter);
It finds the class, because I don't get a ClassNotFoundException, but I
cannot cast it to GeometryPainter (it throws a ClassCastException). Can
someone tell me why? What should I do?