1

Please note the logger info messages and the values of the Longs. .getId() returns a Long value. procDefIdIn is defined as :

private static Long procDefIdIn = null;

procDefIdIn is passed to this class with a value of 131. How does the last line of log info occur? I also tried converting them to Strings using toString(). Same result.

private static void getDefinitions(List<DefinitionProcess> processes)
{
    Long procDefId = null;
    for (Iterator<DefinitionProcess> iterator = processes.iterator(); iterator.hasNext(); ) {
        DefinitionProcess proc = iterator.next();
        if(procDefIdIn != null){
            procDefId = procDefIdIn;

            logger.info(String.format("proc  = #%d procDefIdIn = #%d", proc.getId(), procDefIdIn));

            if(procDefIdIn != proc.getId()){ // How does 131 && 131 get past this?

                logger.info(String.format("Removed proc = #%d", proc.getId()));

                iterator.remove();

                continue;
            }
        }
        else{
            procDefId = proc.getId();
        }

          ........
          //Code here does not execute
         .......

    }
}

INFO - proc = #129 procDefIdIn = #131

INFO - Removed proc = #129

INFO - proc = #130 procDefIdIn = #131

INFO - Removed proc = #130

INFO - proc = #131 procDefIdIn = #131

INFO - Removed proc = #131 //?!?!

1 Answer 1

3

Please use

if(!procDefIdIn.equals(proc.getId())){
Sign up to request clarification or add additional context in comments.

3 Comments

Use .equals() for non-primitive Object comparisons in Java, as this answer illustrates.
Long is not a primitive Data Type
@Sebri Thanks for that and your careful edit after the post :). Yes, I keep forgetting things like that as I am transferring from C++ to Java.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.