java.lang.Boolean more than two Instances -


i have noticed weird behaviour in code of hibersap project (booleanconverter linenumber 75).

the problem boolean value not converted 'x'. have debugged code , inspected boolean expression javavalue == boolean.true. expression interpreted false because javavalue boolean.true , has id 36 , boolean.true has id 33 (the id shown in variables-view of eclipse ide). can inspect instances of boolean , indeed, there 4 instances of java.lang.boolean!!

could please explain me why happening.


edit:

okay, think question isn't precise enough. field should converted boolean , not java.lang.boolean. must classloader fault here. in case conversion boolean boolean done jvm. know every object comparison should use .equals() (and fill in bug) in case should work is. see following code:

public static void main(string[] args) {     for(int = 0; < 1000; i++){         print(true);     }  }  public static void print(object value) {     system.out.println(value); } 

this should not create 1000 java.lang.boolean instances. should always use java.lang.boolean.true! , strange behaviour of code couldn't understand.

maybe side effect of reflection done hibersap? think should not reason such behaviour.

please, want understand.

each time you're doing new boolean(true) or new boolean(false), create new instance of boolean, is, definition, different other instances. objects, except enums, should never compared ==. use .equals() instead. or, in case, use javavalue.booleanvalue().


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -