cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Multiple Accounts + getAccountVariableValue

andrew_holbrook
New Contributor III

Hi,

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:

snapAccount.getAccountVariableValue();

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โ€?

2 REPLIES 2

rreeves
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> {
    @Inject
    FooAccount snapAccount;

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

Thanks! Very helpful.