Hello everyone,
Assume the following :
public class A { }
public class B extends A { }
public class C extends A { }
Now I have interface and base impl
public interface IFacade {
public void method(A a);
}
public class FacadeBaseImpl implements IFacade {
public void method(A a) {
return;
}
Further down I have a concrete classes that know how to deal with B, C:
public class FacadeBImpl extends FacadeBaseImpl {
...
here I would like to implement method in such a way that I would be able to pass to it only B and subclasses of B.
I've tried to do this with Generic methods and it does work, I tried to use lower bounds of generics (extends) on the interface and in FacadeBImpl to define the method with the final class and it does work either. I know I can simply cast inside my method to B, and it works. I would on the other hand prefer something that could catch the error at compile time.
Anyone has any ideas? I would appreciate a tip or two.
Thank you,
Maxim.