java snipped simple if else

hi,
---- true -----
if (1==1) {
return “evet”;
}
else {
return “hayır”;
}

----- false ----------
if ($AKTIF_SAYAC_NO$==$PUANT_SAYAC_NO$) {
return “evet”;
}
else {
return “hayır”;
}

The same loop above gives different results when the variables are different. Why?
My dynamic variables give the same but different (erroneous) result.

Does anyone know about this?

Can you check the details attached?

Thank you.
Best regards.

@emin_bayhan welcome to the KNIME forum

Could you provide us with a simple example that reproduces your problem. That would make is easier to check it out:

Most likely you would have to somehow declare the Java variables in the first place. Like in this example:

1 Like

I built this example from the previous one where you could use a combination of columns and Flow Variable in a simple Java Snippet. It might serve as another inspiration.

The code is like this:

// make the incoming Flow Variable into a Java variable
double v_input_factor;
v_input_factor = $${Dinput_factor}$$;

// convert the double Java variable into a string to use in the code
// https://www.journaldev.com/18380/java-convert-double-to-string
String v_input_factor_string = new StringBuilder().append(v_input_factor).toString();

// capture a possible problem with null values - if not the code might crash
if($var1$ == null) {
  return "missing";
}
else if ($var1$ > v_input_factor) {return "> " + v_input_factor_string;}
else if ($var1$ <= v_input_factor) {return "<= " + v_input_factor_string;}
else {return "something else";}
3 Likes

It may be you need to use if ($AKTIF_SAYAC_NO$.equals($PUANT_SAYAC_NO$)) { in place of if ($AKTIF_SAYAC_NO$==$PUANT_SAYAC_NO$) {

There is a brief explanation of why here - https://dzone.com/articles/identity-vs-equality-in-java

Steve

4 Likes

Thank you for the detailed information. s.roughley :pray:
Best regards.

2 Likes

Thank you for the detailed information. mlauber71 :pray:
Best regards.

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.