How to use the value of a method result based on a test? I have some Java like this:

if (!fooclass.getInfoText().equals(""))
{
    this.setInfoText(fooclass.getInfoText());
}


Is there a neater way of setting one value based on the test results of another value? It seems nasty to me that the method is run twice, but putting the result in a variable when it may be empty and not used at all seems equally messy.

In PHP I might do:

if (($foo = $bar-&gt;baz()) !== "")
{
    $this-&gt;set_info_text = $foo;
}


But I know some people are quite strongly for and against this method, though I can't recall a good justification against it.
I believe fooclass is a reference of Foo class. I can only think about introducing a variable and check it to prevent the double-invokation of same method.

String fooInfo = fooclass.getInfoText();
if (!"".equals(fooInfo))
{
    this.setInfoText(fooInfo);
}


NOTE 

I'm using "".equals(fooInfo) to avoid NPE.