user4359073
user4359073

Reputation:

Coding error when importing project to another computer

I have a project that I created working perfectly without any errors when doing it at home. However when I import the project to a computer at school, I'm getting two code errors from two different classes.

First Error

Main Class

bank.getAccounts().forEach((i,b)->System.out.println(b));

Illegal start of type ) expected;

Illegal start of expression ; expected;

Second Error

BankProcess Class

bankAccounts.remove(bankAccount.getAccountId(), bankAccount);

No suitable methods found for remove....

I could this be happening? No such errors appear on home computer.

package Coursework1;
import java.util.*;

public class Bank {

  //Creates a new treemap in which Bank Accounts will be stored in.
  private TreeMap < Integer, BankAccount > bankAccounts = new TreeMap < Integer, BankAccount > ();

  //This method returns all bank accounts in the treemap.
  public TreeMap < Integer, BankAccount > getAccounts() {
    return bankAccounts;
  }

  //This method adds a bank account to the treemap.
  public void setAccounts(TreeMap < Integer, BankAccount > accounts) {
    this.bankAccounts = accounts;
  }

  //This method return a bank account using the account number.
  public BankAccount getAccount(Integer accountNumber) {
    return bankAccounts.get(accountNumber);
  }

  //This method removes a bank account from the treemap.
  public void removeAccounts(TreeMap < Integer, BankAccount > accounts) {
    this.bankAccounts = accounts;
  }
}

Upvotes: 2

Views: 95

Answers (2)

Sindhoo Oad
Sindhoo Oad

Reputation: 1194

you work with sdk8 at home and there is sdk7 at your school. thats why sdk8 expressions are not supported by sdk7.

Upvotes: 0

peterremec
peterremec

Reputation: 516

As far as i know, forEach statement like yours (lambda expression) is not supported in Java 7 and earlier. So my guess is that school computer doesn't have Java 8 installed.

Upvotes: 4

Related Questions