10-30-2017 02:35 AM
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”?
10-30-2017 08:42 AM
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);
}
}
11-17-2017 11:37 PM
Thanks! Very helpful.