I can not write to JTextArea

0

I have the class:

import javax.swing.JTextArea;

public class Semantico {

private String tipo;
private String variavel;


public void verificaSem(String stipo, String svariavel, JTextArea txtSemantico){

    this.tipo = stipo;
    this.variavel = svariavel;

    String tipo2 = "int";

    if (tipo==tipo2){

        txtSemantico.setText(tipo);
    }


}




}

This txtSemantico is in my main class, and I would like to write the contents of the variable type that is "int" if it is equal to the content of type2 that is also "int". The point is he does not write. Detail, if I take the If condition and leave what's inside the If, it works. Thank you.

    
asked by anonymous 08.06.2016 / 19:09

1 answer

0

Simple, it is a semantic error, when we want to compare two String we do not use the equality operator == , but .equals() , remembering that String is an object, not a variable of primitive type !

  

link

    
08.06.2016 / 21:46