In my class, I have this parameter:
public Long label_id ;
When I try to evaluate the value from label_id which is 0
if(item.label_id == new Long(0)) { Doesn't enter here } else { Enters here }
It is supposed to introduce a condition, since both are equal to zero, but it goes into the else condition. I even tried to debug the code:
label_id Long (id=142) value 0
Did I miss something?
You must first extract the value label_idand then compare it:
label_id
if(item.label_id.longValue() == 0L)
You are using object comparison. and with the new ... you create a new object. both objects do not match ... you can use the new Long (0) .equals (...)
== Java . new Long(0) , , Long.
new Long(0)
equals, NullPointerExceptions`.
equals
if(item.label_id.equals(new Long(0))) { } else { }
,
if(item.label_id == Long.valueOf(0)) { } else { }
@Rocket @ParkerHalo, , new Long(0) .
, if , new Long(0) Long, , , . , ( ). C, ( ) Java. Long , longs .
Long
, new Long(0) , .
- , @ParkerHalo, , long Zero. , , Zero, :
if(item.label_id.longValue() == 0L) {
0 , L longs.
0
L
, !
item.label_id.longValue() == new Long(0).longValue()
item.label_id.equals(new Long(0))
/
Source: https://habr.com/ru/post/1615587/More articles:Is there a way to create a dynamic @ServerEndpoint address in Java? - javaHow to remove ListView GroupStyle Header separator string? - listviewsave JavaFX-ObservableList with JPA - java$ stateParams converting value to string - javascriptHow to make all Builder methods required? - javaMaintaining a truly independent Python installation - pythonкакая разница между AWS Autoscaling и AWS Opsworks - amazon-web-servicesGet Span value using Curl or Python (but when I do it empty)? - pythonShot HTML in summernote - jqueryIs this DWORD code undefined? - c ++All Articles