Showing results for 
Search instead for 
Did you mean: 

Multiple Accounts + getAccountVariableValue

New Contributor III


This may be a dumb java question, I’m trying to call “getAccountVariableValue” from my snap code, but can’t do it unless I put my actual class in parentheses around the call.

So for example, instead of this:


I have to use:
((myFooAccount) snapAccount).getAccountVariableValue();

Is there a way to not have to do this? Perhaps a different way of defining “Account snapAccount”?


Former Employee

It sounds like getAccountVariableValue is a method that applies to each account implementation. Correct me if I’m wrong.

I’d suggest defining an interface that extends Account and defines getAccountVariableValue. Let’s call it FooAccount. Each of your account implementations would implement FooAccount. Note, you could also define a super class for the accounts instead of an interface.

//TODO replace Object with proper types
public interface FooAccount extends Account<Object> {
    Object getAccountVariableValue();

Then modify the snap to inject FooAccount.

public class FooSnap extends SimpleSnap implements MultiAccountBinding<FooAccount> {
    FooAccount snapAccount;

    public Module getManagedAccountModule(final FooAccount account) {
        return binder -> binder.bind(FooAccount.class).toInstance(account);

Thanks! Very helpful.