6

When i compare this constant string with MB inside with a variable with MB inside the result is false. The string constant looks like "MB" ([",M,B,"]=4 length) and my variable is "MB" ([M,B]=2 length). What's wrong here. Java cannot put the quotes inside the code into the string.

string constant

Var 2

public static final String gc_TelCodeFixed  = "FX";

if (!telcode.getId().equals(com.quoka.qis.db.constant.Constants.gc_TelCodeFixed)) 
    throw new TelcodeTypeMismatchException(telcode.getType()); 
Jimbali
  • 2,065
  • 1
  • 20
  • 24
Hasan Tuncay
  • 1,090
  • 2
  • 11
  • 30
  • can you put the comparison code? – sanbhat Apr 09 '13 at 07:37
  • Show some code, not a screen capture please. – Adel Boutros Apr 09 '13 at 07:37
  • 2
    It's "\"MB\"" in java – BlackJoker Apr 09 '13 at 07:39
  • no. I always use equals. For String and for all other types of data. – Hasan Tuncay Apr 09 '13 at 07:41
  • putting a piece of code which does comparison, will help a lot – sanbhat Apr 09 '13 at 07:42
  • 1
    and can you show the Inspect content of telcode.getId() ? – sanbhat Apr 09 '13 at 07:43
  • i added the inspect of telcode.getId() as a second picture. – Hasan Tuncay Apr 09 '13 at 07:48
  • 1
    Did you try invalidating your IDE's caches, or reimporting the project, something like that? This does look very strange. Is it just in the IDE, or is code working in a way consistent with the string being 4 chars long? – yshavit Apr 09 '13 at 07:49
  • the thing i don't understand is. why does java take the quotes inside the constant file into the string? – Hasan Tuncay Apr 09 '13 at 07:49
  • No. There is no integeers involved. getId() gives a string back. That string is 2 char long and ok. the problem is the string inside the constants. It's 4 chars long because the quotes are also inside the string. And i don't know where they come from. – Hasan Tuncay Apr 09 '13 at 07:55
  • @HasanTuncay Thanks for reply. Could you print unicode values of chars in constant string? – default locale Apr 09 '13 at 07:57
  • 6
    I suspect some stale .class file or cache in the IDE. I would do a clean rebuild of the code, and a reimport of the project. – yshavit Apr 09 '13 at 07:58
  • 1
    I also suspect this to be some wierd IDE error. Never seen it before. It looks as if you are using Eclipse, right? I suggest tagging the question with this. – Magnilex Apr 09 '13 at 08:12
  • 1
    I found it. It was two things. I weird IDE error that shows the constants as 4 byte string with quotes and i was comparing integers with string. :-( This funny eclipse behaviour made me looking only for it instead of checking my code properly. – Hasan Tuncay Apr 09 '13 at 09:11

1 Answers1

1

Invisible characters might cause this behavior.

How did the "MB" got there? did you type them or copy-paste from another program? Copy-paste operation might end up with invisible characters and text editors will not show them.

This can be easily reproduced by copying from PDF file with Linux Document Viewer.

Hope this helps, Yaron

Yaron Reinharts
  • 213
  • 1
  • 7