I have an object variable Object test = Spinner.getSelectedItem();
-It gets the selected item from the Spinner (called spinner) and names the item ‘test’
I want to do an if statement related to that object e.g:
'if (test = "hello") {
//do something
}'
But it appears not to work. Do I have to use a different if? or convert the object to string etc.?
The statement:
is an assignment of the string “hello” to the variable test – it doesn’t do a comparison.
is a comparison but still might not work because it compares references. Two different string instances that happen to be both “hello” may not be the same references and therefore the statement may be false.
Try: