In a jLabel component, say I have this codes,
JLabel jLabel = new JLabel();
jLabel.setText( 123 ) ;
It generates error. But writing this,
jLabel.setText( 123 + "" ) ;
force to int part to be a string. But I don’t think writing int like that way is a good idea! Does this method has any overloaded siblings grasping not a String?
Not much you can do here,
setTextonly takes aStringparameter. Alternatively, you could dojLabel.setText(Integer.toString(123)), if you find this more readable.As for
123 + ""part, whenever you add some variables and at least one of them is aString, the compiler will automatically calltoStringon the others and will concatenate all the strings.somevar + ""(empty string) is a quick way of callingsomevar.toString().