cancel
Showing results for 
Search instead for 
Did you mean: 

关于 narrowing cast 的疑问...

Former Member
0 Kudos

请教大家一个问题。

在 ABAP Keyword Documentation 中对 MOVE 的说明中有这样一段话:

Both these statements assign the content of the operand source to the data object destination. The variants with the addition TO or the assignment operator = are valid for all assignments between operands that are not reference variables, and for assignments between reference variables for which the static type of source is more specific than or the same as the static type of destination (narrowing cast).

但是在 ABAP Glossay 中对narrowing cast的说明是:Also called a narrowing cast, a down cast is an assignment between reference variables in which the typr static type of the target variable more specific than the static type of the source variable. A down cast is only possible in assignments with the casting operator (?=) or MOVE ... ?TO. Compare with up cast.

这两段对于narrowing cast的描述是相反的,哪个是正确的?谢谢!

Accepted Solutions (0)

Answers (1)

Answers (1)

YapingGao
Employee
Employee
0 Kudos

Class = Class

目标实例参考的实体类是源实例参考的实体类的父类,或者同一个类。

Interface = Interface

目标实例参考的接口类是源实例参考的接口类的组件,或者同一个类。

Interface = Class

目标实例参考的接口类是实施在源实例参考的实体类或其父类中。

Class = Class

目标实例用object类型声明。

不满足以上任何一个Narrowing Casting条件的,要使用Widening Casting(Down Casting)

就是语法 ?= 或者MOVE...?=...

上面的两条解释应该都没错!

Former Member
0 Kudos

谢谢您的回复。但是我仍然有疑惑:

第一句红色文本指出:narrowing cast:static type of source is more specific than or the same as the static type of destination

第二句红色文本指出:narrowing cast(down cast ):static type of the target variable more specific than the static type of the source variable

这完全是相反的啊...

YapingGao
Employee
Employee
0 Kudos

第一段说的是操作符 = 或者语法MOVE...TO...的概念,第二段说的是 ?= 或MOVE...?TO..

Former Member
0 Kudos

谢谢您的回复。但是不好意思,我还是没有明白。

正如您所说的:

第一段说的是操作符 = 或者语法MOVE...TO...的概念,第二段说的是 ?= 或MOVE...?TO..

但是到底哪个是narrowing cast?

第一段说 ...(narrowing cast)。=> 它是narrowing cast

第二段说 Also called a narrowing cast, a down cast ... => 它也是 narrowing cast,又称 down cast

您说 不满足以上任何一个Narrowing Casting条件的,要使用Widening Casting(Down Casting) => narrowing cast 和 down cast 是相反的

???

Former Member
0 Kudos

不必拘泥于字面的意思,你去看中文Java文档就明白了。关键是你对类的继承是否理解,Cast不过是父类和子类的强制转换而已。

Former Member
0 Kudos

谢谢!