简体   繁体   English

Java - 最大类型参数数

[英]Java - Maximum number of type parameters

I recently read that type parameter names must be exactly one uppercase letter. 我最近读到类型参数名称必须正好是一个大写字母。

If this is the case, then wouldn't there be a maximum number of type parameters? 如果是这种情况,那么不会有最大数量的类型参数吗?

Would said maximum be equal to the number of uppercase letters that are also valid Java identifiers? 表示最大值是否等于也是有效Java标识符的大写字母数?

The convention is to use one letter for a type. 惯例是对一个类型使用一个字母。 However, a type parameter is bound only by the hard limits of an identifier , which is to say, it has to be a valid Java identifier. 但是,类型参数仅受标识符的硬限制的约束,也就是说,它必须是有效的Java标识符。 Any hard limits would only come from that. 任何硬限制都只会来自那个。

There are valid cases in which it's acceptable to break the convention. 有效的案件中,这是可以接受打破惯例。 Specifically, back in the days of Java 7, if you were doing some kind of transformation which required two disjoint types, you could specify it as thus: 具体来说,在Java 7的时代,如果你正在进行某种需要两种不相交类型的转换,你可以这样指定它:

public <DatabaseDataFmt extends DatabaseDTO,
        ProjectionFmt extends ProjectionDTO,
        Result>
  Result transform(DatabaseDataFmt databaseFormat,
                   ProjectionFmt projectionFormat) {}

Ultimately it depends on what you want to accomplish with your identifiers. 最终,这取决于您希望使用标识符完成的任务。 Convention helps , but if it doesn't help , then there's no reason to be bound by it. 公约有所 帮助 ,但如果没有帮助 ,那么就没有理由受其约束。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM