Q:

Two interfaces specify methods with the same signature, but specified to have different behavior?

I have some class public class myClass implements A, B where A and B both contain a method  public int doSomething();, but A.doSomething is specified by the interface to do something different than B.doSomething.
I have read Two interfaces with same method signature implemented in Java class, but that doesn't really address my problem, because the methods are overriden to do the same thing, but as I said above, my question is about when they are specified in the interfaces to do different things.
For example, suppose A.doSomething() is supposed to return 0, while B.doSomething() is supposed to throw an exception, and violating either one wold cause problems for methods that are supposed to take them as parameters.
Is there any way to do this in java?  If so, how would one actually do it?

A:

As per JLS  (This is similar case like what you want, may not exact)
interface Fish { int getNumberOfScales(); }
interface StringBass { double getNumberOfScales(); }
class Bass implements Fish, StringBass {
    // This declaration cannot be correct, no matter what type is used.
    public ??? getNumberOfScales() { return 91; }
}

It is impossible to declare a method named getNumberOfScales whose signature and return type are compatible with those of both the methods declared in interface Fish and in interface StringBass, because a class cannot have multiple methods with the same signature and different primitive return types (§8.4).
Unless you change your design by adding proxy (or) method signature it is not possible to do what you are expecting.

A:

You might be able to use a Proxy instance to do this. See this question for info on Proxy (particularly, the second part of the answer.)
The InvocationHandler that you write would check to see which interface is being used to call the method and delegate to the appropriate method inside your object. Here's what your implementation looks like:
public class MyClass {
    // Note that we aren't implementing the interfaces anymore

    public int doSomethingForA() {
        return 0;
    }

    public int doSomethingForB() {
        throw new IllegalArgumentException();
    }
}

Then your InvocationHandler:
public class MyClassInvocationHandler implements InvocationHandler {

    private MyClass target;

    public MyClassInvocationHandler(MyClass target) {
        this.target = target;
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        try {
            if (method.getDeclaringClass().equals(InterfaceA.class))
                return MyClass.getMethod("doSomethingForA").invoke(target, args);
            else if (method.getDeclaringClass().equals(InterfaceB.class))
                return MyClass.getMethod("doSomethingForB").invoke(target, args);
            else
                throw new UnsupportedOperationException("Unsupported interface: " + method.getDeclaringClass());
        } catch (NoSuchMethodException ex) {
            throw new UnsupportedOperationException("Method not found", ex);
        } catch (IllegalAccessException ex) {
            throw new UnsupportedOperationException("Method was not public", ex);
        } catch (InvocationTargetException ex) {
            // May throw a NullPointerException if there is no target exception
            throw ex.getTargetException();
        }
    }
}

Then to create the proxy, you'll pass in both interfaces:
Proxy.newProxyInstance(null, new Class<?>[] { InterfaceA.class, InterfaceB.class }, new MyClassInvocationHandler(mc));

I think this will work. When you call it using one interface or the other:
MyClass mc = new MyClass();
Object proxy = Proxy.newProxyInstance(null, new Class<?>[] { InterfaceA.class, InterfaceB.class }, new MyClassInvocationHandler(mc));
InterfaceA a = (InterfaceA) proxy;
a.doSomething();
InterfaceB b = (InterfaceB) proxy;
b.doSomething();

Then it should pass in Method objects with different declaring classes. I'm not sure if this is how it works though, so this will need to be tested.

