您在使用显式类型构造函数时需要进行权衡。
You'll need to evaluate the tradeoffs in using an explicit type constructor.
显式类型语言要求声明每个变量和每个函数参数。
A manifestly typed language forces you to declare each variable and each function argument.
这里有一份关于scala何时需要显式类型注解规则的总结。
Here is a summary of the rules for when explicit type annotations are required in Scala.
没有显式类型参数时,会使用类型推理来确定函数的参数类型。
When there are no explicit type parameters, type inference is used to determine the types of parameters of functions.
Scala使用类型注解作为显式类型声明的方式,比如HashMap。
Scala USES the term type annotations for explicit type declarations like HashMap.
此程序还演示了静态字段初始值设定项如何在显式类型构造函数中的代码之前执行。
This program also demonstrates how static field initializers execute before the code inside an explicit type constructor.
静态类型语言通常是显式类型的,但也不完全是;而动态类型语言几乎都是隐式类型的。
Statically typed languages are usually, but not exclusively, type explicit; dynamically typed languages are almost always type-inferred.
变量的显式类型化(即将变量声明为String或Collection)依然是可选的。
Explicit typing of variables (that is, declaring a variable as a String or Collection) is still optional.
如果范围变量是显式类型的,请确保该类型与循环访问的集合中的元素类型相同或可从该类型隐式转换。
If the range variable is explicitly typed, make sure that the type is either the same as, or implicitly convertible from, the type of the elements in the collection it iterates.
这个异常是由显式类型转换抛出的,因为测试用例试图把类型为String 的东西转换成Integer。
The exception is thrown by the explicit cast because the test case is trying to convert something of type String to an Integer.
当存在显式类型构造函数时,编译器不会用beforefieldinit标记该类型,精确的计时限制会导致FxCop所暗示的性能下降。
When an explicit type constructor is present, the compilers will not mark the type with beforefieldinit, and the precise timing restrictions lead to the performance drop hinted at by FxCop.
原来的查询比较一个字符串和一个数字,但是在修改后的查询中执行了显式的类型转换。
Here the original query is comparing a string to a number but in the modified query, explicit type-casting has been done.
尽管如此,正如类型推论所说,在很多情况下我们不需要显式指定类型。
Nevertheless, because of type inference, in many cases no types have to be explicitly specified.
通过安排不同类型的对象来执行公共方法,我们将分派决定移到对象中并从显式条件块中消除。
By arranging for objects of different types to implement common methods, we move the dispatch decision into the objects and out of an explicit conditional block.
只有当应用程序实际上需要该类,而不是在编译或运行时过程中,此类的类型才成为显式的。
The class type will become explicit only when the application actually needs the class, not during compile or run time.
应用程序请求显式的可信连接时,不能将数据库服务器验证类型设置为CLIENT。
If your application requests an explicit trusted connection, you cannot set the database server authentication type to CLIENT.
相对于显式说明返回哪个数据类型来说,客户端开发者需要从现有的字段中进行推断。
Instead of explicitly saying what data type is being returned the client developer has to infer it from the fields that are present.
让我们来看一些需要显式声明方法返回类型的例子。
Let's look at examples where explicit declarations of method return types are required.
它证明了该CLI规范还同时保证了运行库不允许类型构造函数产生死锁的情形,除非用户代码显式采用了附加锁。
It turns out the CLI specification also guarantees that the runtime will not allow type constructors to create a deadlock situation, unless additional locks are explicitly taken by user code.
重载的方法有时候也需要显式返回类型。
Overloaded methods can sometimes require an explicit return type.
当使用变量时,它不应该显式声明为任何类型,除非是Any,这样它才能匹配所有情况。
When using a variable, it should have no explicit type or it should be declared as any, so it can match anything.
类型推断使得显式的类型声明信息在大多数场合下减少到了最低。
Type inference minimizes the need for explicit type information in many contexts.
例如,在Oracle中字符串'1 '可以与数字1比较,但是在DB 2中需要执行显式的类型转换。
For example, in Oracle, a string '1' can be compared with a numeric 1, but in DB2, explicit type-casting needs to be done.
当在代码里显式地为变量指定类型信息时,类型注解应该跟在变量名的冒号后面(也就是类pascal语法)。
When explicit type information for variables is written in the code, these type annotations follow the colon after the item name (i.e., Pascal-like syntax).
XSLTv2的新特性之一就是为您的变量和参数提供显式数据类型的能力。
One new feature of XSLT v2 is the ability to provide an explicit data type for your variables and parameters.
在清单16中,复杂类型定义包含一个由4个显式定义的子元素组成的序列。
In Listing 16, the complex type definition contains a sequence of four child elements that are explicitly defined.
注意,解组将创建一个泛型对象,因此您必须将其显式设置为 SimpleBean类型。
Note that the unmarshalling creates a generic object, so you must explicitly cast it to the SimpleBean type.
Scala通常可以推断出方法的返回值(但是方法参数的类型就不行了),所以我们不用显式声明。
Scala can usually infer the return type of the method (but not the types of the method arguments), so we drop the explicit declaration.
与Bike和自行车商店类型一样,Groovy的CommandLineView没有了为rentabike属性所显式编写的getter或setter的冗余。
As with the bike and bike store types, the Groovy's CommandLineView doesn't have the noise of an explicitly coded getter or setter for the RentABike property.
当然,我们可以完全不使用显式的范围,只要能确保没有用不适当的类型来实例化类型参数。
Of course, we could simply leave off the explicit bound and just make sure that we never instantiate the type parameter with an inappropriate type.
应用推荐