попробуйте следующее:
public String myMethod() { if(condition) { return x; } return ""; //returns empty string }