In java I’m trying to use shorthand variable assignment like below. Currently owner is assigned on a different line but I’d like to put it on the same line as below. This isn’t working – is it not possible or is there another route?
if ((User owner = search.getOwner()) instanceof User && owner.getId() != null) {
searchQuery.append("owner_id = :ownerId AND ");
queryMap.put("ownerId", owner.getId());
}
Thanks
In Your code owner is declared locally in the scope of if condition. Try this code modification