简体   繁体   English

错误 DART:名称“x”不是类型,因此不能用作类型参数

[英]ERROR DART: The name 'x' isn't a type so it can't be used as a type argument

Error in the Input part in one class and in Output in another class一个 class 和另一个 class 中的 Output 中的输入部分出错

  1. This would be the main class referenced这将是参考的主要 class
abstract class HttpFunction<Input, Output>
{
  Output apply(Input paramInput);
}
  1. This would be the class in which the previous one is called这将是 class 其中前一个被称为
class ComposerFunction with HttpFunction<Input, Request>
{
    RequestComposer<Input> inputConverter;

    ComposerFunction(RequestComposer inputConverter);

    ComposerFunction_(RequestComposer<Input> inputConverter)
    {
        this.inputConverter = inputConverter;
    }

    Request apply(Input input)
    {
        return this.inputConverter.compose(input);
    }
}

class InterpreterFunction with HttpFunction<Response, Output> 
{
    ResponseInterpreter<Output> responseInterpreter;

    InterpreterFunction(ResponseInterpreter outputConverter);

    InterpreterFunction_(ResponseInterpreter<Output> responseInterpreter)
    {
        this.responseInterpreter = responseInterpreter;
    }

    Output apply(Response response)
    {
        return this.responseInterpreter.interpret(response);
    }
}
  1. These are the Errors这些是错误
The name 'Input' isn't a type so it can't be used as a type argument.
Try correcting the name to an existing type, or defining a type named 'Input'.dart(non_type_as_type_argument)

And

The name 'Output' isn't a type so it can't be used as a type argument.
Try correcting the name to an existing type, or defining a type named 'Output'.dart(non_type_as_type_argument)

UPDATE更新

class ComposerFunction<Input> implements HttpFunction<Input, Request>
{
    ...
}

class InterpreterFunction<Output> implements HttpFunction<Response, Output>
{
   ...
}

Thank you for your answers:)谢谢您的回答:)

If generically passing types is what you're after, could you try changing your abstract class as below如果一般传递类型是您所追求的,您是否可以尝试更改您的抽象 class 如下

abstract class HttpFunction<T, U>
{
  U apply<T, U>(T paramInput);
}

And the classes as follows:类如下:

class ComposerFunction with HttpFunction<Input, Request>
{
    RequestComposer<Input> inputConverter;

    ComposerFunction(RequestComposer inputConverter);

    ComposerFunction_(RequestComposer<Input> inputConverter)
    {
        this.inputConverter = inputConverter;
    }

    Request apply<Input, Request>(Input input)
    {
        return this.inputConverter.compose(input);
    }
}
class InterpreterFunction with HttpFunction<Response, Output>
{
    ResponseInterpreter<Output> responseInterpreter;

    InterpreterFunction(ResponseInterpreter outputConverter);

    InterpreterFunction_(ResponseInterpreter<Output> responseInterpreter)
    {
        this.responseInterpreter = responseInterpreter;
    }

    Output apply<Response, Output>(Response response)
    {
        return this.responseInterpreter.interpret(response);
    }
}

This is assuming you have classes created/referenced of the expected types这是假设您创建/引用了预期类型的类

You have:你有:

class ComposerFunction with HttpFunction<Input, Request>
{
   ...
}

Assuming that you want ComposerFunction to be a generic class that can be parameterized on caller-specified Input and Request types, you have not declared ComposerFunction to be a generic class.假设您希望ComposerFunction成为通用 class 可以在调用者指定的InputRequest类型上进行参数化,您尚未将ComposerFunction声明为通用 class。 Although HttpFunction is a generic class, ComposerFunction as written is a non -generic class that uses HttpFunction specialized with types literally named Input and Request .尽管HttpFunction一个通用的 class,但ComposerFunction是一个通用的HttpFunction ,它使用专门的类型为InputRequest的 HttpFunction 。 If you don't have classes named Input and Request , this therefore fails with:如果您没有名为InputRequest的类,那么这将失败并显示:

The name 'Input' isn't a type so it can't be used as a type argument.名称“输入”不是类型,因此不能用作类型参数。

to make ComposerFunction a generic class, you need to add type parameters to it :要使ComposerFunction成为通用 class,您需要向其添加类型参数:

class ComposerFunction<Input, Request> with HttpFunction<Input, Request>
{
   ...
}

Same thing applies to InterpreterFunction .同样的事情也适用于InterpreterFunction

Additionally, with is normally intended for use with mixin s .此外, with通常用于mixin It's also allowed with abstract class for backward compatibility with Dart 2.0 and earlier, but since HttpFunction does not provide any code that can be reused, this doesn't seem useful. abstract class也允许与 Dart 2.0 及更早版本向后兼容,但由于HttpFunction不提供任何可重用的代码,这似乎没有用。 If you want ComposerFunction (and InterpreterFunction ) to conform to an interface, then you usually would use implements instead.如果您希望ComposerFunction (和InterpreterFunction )符合接口,那么您通常会改用implements

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 名称“任务”不是类型,因此不能用作类型参数。 | 颤振与飞镖 - The name 'Task' isn't a type so it can't be used as a type argument. | Flutter & Dart User 不是类型,因此不能用作类型参数 - User isn't a type so it can't be used as a type argument 名称“GeolocationStatus”不是类型,因此不能用作类型参数 - The name 'GeolocationStatus' isn't a type so it can't be used as a type argument 名称“Articles”不是类型,因此不能用作类型参数 - The name 'Articles' isn't a type so it can't be used as a type argument 名称 appstate 不是类型,因此不能用作类型参数 - the name appstate isn't a type so it can't be used as a type argument 名称“列表”不是类型,因此不能用作类型参数。 尝试将名称更正为现有类型,或定义名为“列表”的类型 - The name 'List' isn't a type so it can't be used as a type argument. Try correcting the name to an existing type, or defining a type named 'List' 名称“XFile”不是类型,因此不能用作类型参数。 尝试将名称更正为现有类型,或定义名为“XFile”的类型 - The name 'XFile' isn't a type so it can't be used as a type argument. Try correcting the name to an existing type, or defining a type named 'XFile' Flutter 名称 FutureOr 不是类型,因此不能在 as 表达式中使用 - Flutter The name FutureOr isn't a type, so it can't be used in an as expression 名称 'string' 不是类型,不能在 'is' 表达式中使用 - The name 'string' isn't a type and can't be used in an 'is' expression Dart 扩展 - 获取“不是类型”错误 - Dart extension - Getting "isn't a type" error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM