why two aliases to “array of string” treated differently?

前端 未结 3 1843
南旧
南旧 2020-12-03 21:26

In Pascal there are two kinds of type declarations:

  • type aliases: type NewName = OldType
  • type creation: type NewType = type
3条回答
  •  星月不相逢
    2020-12-03 22:25

    Delphi is a strongly typed language. That means that identical (in this case I mean their definitions look exactly the same) types are not assignment compatible.

    When you write array of you are defining a type and not an alias. As David already said in his comment the two identical types like

    type 
      T1 = array of string; 
      T2 = array of string;
    

    are not assignment compatible.

    Same goes for

    type
      TStringDynArray = array of string;
      TArray = array of string;
    

    Often people forget about the incompatibility of identical types and my guess would be that they did when they introduced IOUtils for example. Theoretically the definition of TStringDynArray should have been changed to TStringDynArray = TArray but I guess that could have raised other problems (not saying bugs with generics...).

提交回复
热议问题