Common ancestor of BeanItemContainer and SQLContainer

I had an existing custom component I programmed some time ago. It used to use SQLContainer as its container (yeah, I know, v7). Now I’m getting tired of using it and extended my class in order to allow using BeanItemContainer, too.

The problem is that I was accessing its datasource for several operations, and I was explicitly casting to SQLContainer here and there.

Now I hoped both SQLContainer and BeanItemContainer were implementing the same methods from the same interface where I’m using methods on datasource and I could simply change my casting to a common ancestor of both SQLContainer and BeanItemContainer. But unfortunately my assumption was wrong.

I just got aware of the possibility that brings Java 8 of casting to more than one interface, and I almost got it working - until I discovered that removeContainerFilters(), a method that exists on both SQLContainer and BeanItemContainer, is not defined in an interface I can cast my datasource to.

I finally could compile my app by the ugly method of do a

if(dataSource instanceof BeanItemContainer){
...
}
else if(dataSource instanceof SQLContainer){
...
}

but, of course, that’s rather ugly.

As I’ve been considerably messing around with this and now my brain is rather polluted, it would be great to hear from a smarter suggestion on how to approach this. Of course, appart from migrating to V8 and getting totally rid of containers, something I still cannot attempt yet.

Thanks once again :wink: