W
WillieLWZ
Please consider:
===================
public class ClassA {
public void someMethod(ClassB objB) {
//...
}
}
===================
public class ClassB {
}
===================
public class SubClassB extends ClassB {
}
===================
public class Main {
private static class SubClassA extends ClassA {
public void someMethod(ClassB objB) {
if (objB instanceof SubClassB) { //<------ see question
below
//...
} else {
super.someMethod(objB);
}
}
}
private ClassA objA = new SubClassA();
public ClassA getClassA() {
return objA;
}
}
====================
Question: Can I avoid the use of the "instanceof" operator, if yes how?
With thanks,
Willie
===================
public class ClassA {
public void someMethod(ClassB objB) {
//...
}
}
===================
public class ClassB {
}
===================
public class SubClassB extends ClassB {
}
===================
public class Main {
private static class SubClassA extends ClassA {
public void someMethod(ClassB objB) {
if (objB instanceof SubClassB) { //<------ see question
below
//...
} else {
super.someMethod(objB);
}
}
}
private ClassA objA = new SubClassA();
public ClassA getClassA() {
return objA;
}
}
====================
Question: Can I avoid the use of the "instanceof" operator, if yes how?
With thanks,
Willie