//all psuedo code i.e. will not compile
Class Shape
{
abstract Integer area(); // must be implemented in a child class
abstract void printSides(); // must be implemented in a child class
}
Class EqualateralTriangle extends Shape
{
Integer area() // implements Shape.area() for regular triangles
{
return (sqrt(3) / 4) * sqr(side);
}
void printSides() // implements Shape.printSides() for regular triangles
{
print(side); // 3 equal sides
print(side);
print(side);
}
}
.
.
Shape shp;
EqualateralTriangle t = new EqualateralTriangle(4);
system.print(t.area()); // valid output of 6.93
shp = t; // make use of the EqualateralTriangle t via shp which is a Super class (and so valid) referencing variable.
shp.area(); //valid because a EqualateralTriangle IS (extends) a Shape
.
.
CASTING:
Class ShapePrinter
{
void printShape(Shape s)
{
//We don't know what shape (EqualateralTriangle, Square, Circle) we will get so interface incoming object using a 'Shape' reference
s.printSides();
}
}
String str = new String();
EqualateralTriangle t = new EqualateralTriangle(4);
Shape shp = t;
ShapePrinter sp = new ShapePrinter();
sp.printShape((Shape)t); //(Shape) converts EqualateralTriangle perspective of 't' into a Shape perspective i.e. it CASTS ET into S
sp.printShape(shp); // shp is a 'Shape' perspective on t since an ET IS an S
sp.printShape(t); // in this situation, compiler knows an ET IS an S so the casting is done implicitly
sp.printShape(str); // No such method accepting a String
sp.printShape((Shape)str); // <--- java.lang.String cannot be cast into Shape.
sp.printShape(sp); // No such method accepting a ShapePrinter
sp.printShape((Shape)sp); // <--- ShapePrinter cannot be cast into Shape.
So in your case you might have a method that accepts a URLClassLoader e.g.
Class Profiler
{
static void LoadClassToProfile(URLClassLoader ucl) //static so don't create a Profiler just use 'Profiler.method()'
{
//blah... blah...
}
}
somewhere in your code you might have a URLClassLoader:
URLClassLoader u = new StandardURLClassLoader("https://myserver.com/trading/bin/mystrategy.class"); //Think Shape/EqualateralTriangle, a StandardURLClassLoader IS a URLClassLoader
you might also have one of those greed compiler objects in your code:
com.dukascopy.dds2.greed.agent.compiler.c comp = new com.dukascopy.dds2.greed.agent.compiler.c(); //variable here is 'comp'
with this in place you might try:
Profiler.LoadClassToProfile(u); //valid use of your URLClassLoader
or
Profiler.LoadClassToProfile(comp); //compiler will complain that LoadClassToProfile expects a URLClassLoader and no method found that accepts anything else
which might lead to a CAST attempt to beat the error
Profiler.LoadClassToProfile((URLClassLoader)comp); //java.lang.ClassCastException:com.dukascopy.dds2.greed.agent.compiler.c cannot be cast to java.net.URLClassLoader
Some methods do not specify the type of objects they take explicitly, e.g:
Class Profiler
{
static void LoadClassToProfile(Object someClassLoader) //<---- generic OBJECT type to hold reference to ALL incoming class types
{
//use Java Reflection to CAST 'someClassLoader' into the java.net.URLClassLoader object we ultimately expect
//if 'someClassLoader' happens to be a String, Greed Compiler, anything other than an instance of URLClassLoader (or one of it's sub-class type)
//then we get an error of the form: <Actual CLASS TYPE of 'someClassLoader'> cannot be cast to java.net.URLClassLoader
}
}
Hope you understand the underlying idea a bit better.