public static Type[] getReturnTypes(Invocation invocation) {
        try {
            if (invocation != null
                    && invocation.getInvoker() != null
                    && invocation.getInvoker().getUrl() != null
                    && invocation.getInvoker().getInterface() != GenericService.class
                    && !invocation.getMethodName().startsWith("$")) {
                Type[] returnTypes = null;
                if (invocation instanceof RpcInvocation) {
                    returnTypes = ((RpcInvocation) invocation).getReturnTypes();
                    if (returnTypes != null) {
                        return returnTypes;
                    }
                }
                String service = invocation.getInvoker().getUrl().getServiceInterface();
                if (StringUtils.isNotEmpty(service)) {
                    Method method = getMethodByService(invocation, service);
                    if (method != null) {
                        returnTypes = ReflectUtils.getReturnTypes(method);
                    }
                }
                if (returnTypes != null) {
                    return returnTypes;
                }
            }
        } catch (Throwable t) {
            logger.warn(COMMON_REFLECTIVE_OPERATION_FAILED, "", "", t.getMessage(), t);
        }
        return null;
    }
@Test
    void testGetReturnTypesWhenGeneric() throws Exception {
        Class<?> demoServiceClass = DemoService.class;
        String serviceName = demoServiceClass.getName();
        Invoker invoker = createMockInvoker(
                URL.valueOf(
                        "test://127.0.0.1:1/org.apache.dubbo.rpc.support.DemoService?interface=org.apache.dubbo.rpc.support.DemoService"));

        RpcInvocation inv = new RpcInvocation(
                "testReturnType", serviceName, "", new Class<?>[] {String.class}, null, null, invoker, null);
        inv.setMethodName($INVOKE);
        Type[] types = RpcUtils.getReturnTypes(inv);
        Assertions.assertNull(types);

        RpcInvocation inv1 = new RpcInvocation(
                "testReturnType1", serviceName, "", new Class<?>[] {String.class}, null, null, invoker, null);
        inv1.setMethodName($INVOKE);
        java.lang.reflect.Type[] types1 = RpcUtils.getReturnTypes(inv1);
        Assertions.assertNull(types1);

        RpcInvocation inv2 = new RpcInvocation(
                "testReturnType2", serviceName, "", new Class<?>[] {String.class}, null, null, invoker, null);
        inv2.setMethodName($INVOKE);
        java.lang.reflect.Type[] types2 = RpcUtils.getReturnTypes(inv2);
        Assertions.assertNull(types2);

        RpcInvocation inv3 = new RpcInvocation(
                "testReturnType3", serviceName, "", new Class<?>[] {String.class}, null, null, invoker, null);
        inv3.setMethodName($INVOKE);
        java.lang.reflect.Type[] types3 = RpcUtils.getReturnTypes(inv3);
        Assertions.assertNull(types3);

        RpcInvocation inv4 = new RpcInvocation(
                "testReturnType4", serviceName, "", new Class<?>[] {String.class}, null, null, invoker, null);
        inv4.setMethodName($INVOKE);
        java.lang.reflect.Type[] types4 = RpcUtils.getReturnTypes(inv4);
        Assertions.assertNull(types4);

        RpcInvocation inv5 = new RpcInvocation(
                "testReturnType5", serviceName, "", new Class<?>[] {String.class}, null, null, invoker, null);
        inv5.setMethodName($INVOKE);
        java.lang.reflect.Type[] types5 = RpcUtils.getReturnTypes(inv5);
        Assertions.assertNull(types5);
    }