-2

I have the code below in an Android method. When I debug the code the value of callType is "upload_latest" and the value of uploaded_date (defined as long) is 1424286105554, but code execution bypasses the "return false" statement and goes straight to the string declaration below it. I know I've missed something obvious but can't work out what it is - can anyone help?

if (callType == "upload_latest" && uploaded_date > 0) {
    return false;
}
String extension = "";
Ian M
  • 567
  • 8
  • 33

4 Answers4

1

If callType is of type String (or any other non-primitive type), you need to use the .equals() method rather than the == operator. See this question for more information.

Community
  • 1
  • 1
emerssso
  • 2,376
  • 18
  • 24
0

To compare String values use .equals, == tests for reference equality.

callType.equals("upload_latest")

Manuel Ramírez
  • 2,275
  • 1
  • 13
  • 15
0

Try something like this:

if ((callType.equals("upload_latest"))&& (uploaded_date > 0))) {
    return false;
}
String extension = "";
apmartin1991
  • 3,064
  • 1
  • 23
  • 44
0

use callType.equals("upload_latest") instead of callType == "upload_latest"

The == operator checks to see of the strings are the same instance where .equals() checks to see if they represent the same character sequence.

nerdy900
  • 338
  • 2
  • 8