String equals in Android studio

Was just wondering why I get

Cannot resolve symbol ‘equals’

on the string.equals. Im using andriod studio.

public class Transaction {

    String type;
    double amount;

    if(type.equals("Deposit")){


    };


}

Answer

You have to write your test in a function like :

public class Transaction {

    String type;
    double amount;

    public void testType() {
        if(type.equals("Deposit")) {


        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *