import org.jetbrains.annotations.NotNull; public class Test { private R getR() { return null; } public void main(String[] args, T param) { MyResult myVariable = getTrMyResult(param); System.out.println("Custom(" + myVariable.t() + ", " + myVariable.r() + ")"); } private @NotNull MyResult getTrMyResult(T param) { T t = param; R r = getR(); System.out.println(); MyResult myVariable = new MyResult<>(t, r); return myVariable; } private record MyResult(T t, R r) { } }