[Solved] Confusion as to initialization (or lack thereof) of object


This is the problem:

AccountManager accountmanager= new AccountManager (account, t, accountmanager);

You’re declaring a variable, and trying to read from that variable in the same statement that gives it an initial value.

Here’s a simpler example, to show how it’s nonsensical:

int y = 10;
int x = y + x;

What would you expect the value of x to be at the end of that? You’ve said its initial value should be the value of y plus its current value… but it doesn’t have a current value, because you’re trying to find its initial value!

I strongly suspect that you shouldn’t have that their constructor parameter at all though. Why does one AccountManager need a reference to another? You should:

  • Remove the accountmanager field
  • Remove the accountmanager constructor parameter
  • Change the local variable declaration and initialization to:

    AccountManager accountManager= new AccountManager(account, t);
    

    (Note the capital M in accountManager, to follow Java naming conventions. I’d probably rename t to transaction for clarity too.)

2

solved Confusion as to initialization (or lack thereof) of object