Go言語仕様(タイプと値の属性)

6715 ワード

      :http://golang.org/doc/go_spec.html
      :    ([email protected])
Propties of types and valuesタイプと値の属性Two types are eigther dentical or different、and they are eincomptible or incomptible.Identical types are always comptible、but comptible types need nodenticalタイプは同じではありません。同じタイプは常に互換性がありますが、互換性のタイプは必ずしも同じではありません。Type identity and comptibilityタイプの整合性と互換性Type identityタイプの一致性Two named types are dentical if their type names originate in the same type declaration(§Declarations and scope)A named and an unnamed type are never identical.Two unnamed types are identical if the corese ponding type liverals the same live the same tructure and cores ponents have identical types.In detail:このタイプが同じなら、二つの宣言が作成されます。名前の種類と名前のないタイプは違います。名前のない2つのタイプが同じ構造を持ち、対応するコンポーネントが同じタイプを持っている場合、この2つのタイプは同じである。詳細:Two array types aridentical if they have identical element types and the same array length.Two slice types aress aritical feel types.Two struct types.Two struct types arititite e of the fielmens。and if corereposisis corereponding fields have the same names and dentical types.Twoannymous fields are considededededed the same me name.Twopointertypes arartitititititititititititititititititifefefefefetypes.Two function tytytytytytytytytytytytytytytytytytytytypes.tttttttttttttttthethethethethethethethethethethethethethethethethethethethedededededededededededededededededededededededededededededededededearidenticl.All"…"parameters without a specified type are defined to have identical type.All"…"parameters with specifed dentical type T are defined to have dentical type.Parameters and rerelt names arare not required to match.Two interface types are e e e e dentical the same set of me set of methods with thethererererererereredes thethe sadedededededededededededes thethethethethethethethethethe sasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasame me me me me me me me me me me me ve identical keyand value types.Two chanel types are identical if they have identical value types and the same direction.もし2つの配列の長さが元素タイプと同じなら、それらは同じです。二つのスライスが同じ要素タイプがあるなら、それらは同じです。二つの構造体が同じメンバー変数順序を持ち、対応するメンバー名が同じであり、対応するメンバータイプが同じであれば、それらは同じである。2つの構造体の匿名のメンバは同じ名前であると考えられる。二つのポインタが同じベースタイプがあるなら、それらは同じです。二つの関数パラメータの個数と戻り値の個数が同じで、パラメータと戻り値が対応するタイプが同じであれば、それらは同じです。すべてのタイプが指定されていません。「…『パラメータは同じと考えられています。パラメータと返却値の名称は同じではありません。2つのインターフェースに同じ方法セットがあり、方法名と関数タイプが同じであれば、同じです。方法の順序は同じではありません。2つのmapに同じキーパッドタイプがあれば、それらは同じです。もし2つのチャンネルに同じ値タイプと方向があります。」Type comptibilityタイプ互換性Type comptibility is less stingnt than type dentity:a named and unnamed type are comptitype the rective type litype ares.Inalother fidentite''substituted for`identical'.タイプ互換性はタイプが同じではないので厳密です。名前と名前がないタイプはタイプが互換性があると互換性があります。その他、タイプ互換性の定義は上記のタイプと一致しています。同じ互換性にのみ変換されます。Given the declarationsは以下のようなtypeを示します。T 4 func(int,float)*T 0 T 5 func(x int,y flotoat)*T 3 struct{a,c int)T 3 struct{a,c int T 4 func(int,float)*[]string)these types arititical:これらは同じです:T 0 andT 0 andT 0[intint and and and and and and[int and and[int]ststststucuct fefefefefet{stfut ftftfut{5、stfut、stfut ftfut、stfefefefefefefeatfttfttfttftftftftfttttf*[] string)T 0 and T 1 are neither dentical nor comptible because they are named types with distinct declarations.T 0とT 1は同じタイプではなく、異なるタイプ名として宣言されているので、これらは互換性があります。Tand Tflunt 0 and Tstrystring T 2 and struct{a,c int}are incomptible because they have different field names.T 2とstruct{a,c int}互換性がないので、メンバー名が違います。Asignment comptibility互換性A value v of static type V is assignment comptible with a type T if one or more of the following condititions:以下の条件を満たすと、Vタイプの変数vはT型変数と値を与えられます。V is comimipatible with T.T.T isis an interface type and V implemens T.V is a pointer to an array and T isa sslalilice typewith copatible elementype and at least one of V or T or T is unnamed.Afterassisisisigmenment、thessasasasasasasasisisisisisisisisisisisisisisisisisisisisisisigmenmenment、the the thesthessssthesssssthessssmimimimimimimimimimimimimimimimimimimimimimimimimimimimimimimimipatible element type and at least one of V or T is unnamed.VはTと互換性があります。Tはインターフェースであり、VはインターフェースTを実現しました。Vは配列を指すポインタで、Tはスライスであり、それらの元素タイプは互換性があります。TまたはVは少なくとも一方に名前がないです。分布後スライスタイプ変数は元の配列を指します。元素はコピーされません。Vはチャネルです。一つはVと互換性のあるタイプのチャネルであり、その両方も少なくとも匿名の方がいます。If T is a struct type、eigther all fields of T must be exportd、or the assignment must be in the same package in which T is declead.In other world、a structive of stressindividually by the program.Tが構造体のタイプであれば、すべてのメンバー変数が公有であるか、または割り当て値が宣言Tのパケット内で発生します。言い換えれば、構造体を他の構造体に割り当てたいなら、その構造体のメンバー変数ごとにプログラムに合法的に値が付けられます。An untyped constant compingsigment。ible with type T if v can be represented accurately as a value of type T.vがTタイプであれば、名前のない静的定数vがTタイプの割り当てに対応することができます。The predied identifer nil assigment comptible with any pointer、function、snenter、slanter、slectureアイデンティティーnilと任意のpointer、funciton、slice、map、chanel、interfaceタイプの互換性があります。そのタイプの0値を表します。Any value may be astined to the blank identifer。どの値でも空白の識別子のために値が付けられます。Comprion comptibilityは互換性のExcept of parther。tatic type.Values of integer、float at-point、and string type may be compred using the full range of compris operators;boleans and complext values may be compred only for equality.inequality.他に指定されていない限り、すべてのタイプの変数と静的な比較が可能です。すべての比較子で比較できます。ブール型と複素型の値は、それらが等しいかどうかを比較するだけです。    Values of compsite type may be compred for equality or inequality using the=and!=operators、with the follwing provisos:合成タイプの値は=と!=で比較できますが、以下の状況に注意してください。y only be compred explicity against nil.A slice value is equal to nil if it has been assigned the explicit value nil、if it is uninitialized、or if it has beness another slice value value value value nil変数がない場合は1つの変数です。このカットはnilに等しいです。An interface value is equal to nil if it has bened the explicit value nil、if it is unitialized、or if it haned another interface valuequal to nil.インタフェースの場合とForequare ofunequal if one equals nil and one does not.すべてのエネルギーとnilを比較し、同じタイプの2つの値があるときだけnilを待つと、それらは同じです。nilが別のものでなければ、それらは等しくありません。Pointer values are equal the y point to the same location。ポインタは同じ位置を指すだけでFrequalvance vance vanctionです。fer to the same function.関数は同じ関数を参照する必要があります。Chanel and map values are equal if they were created by the same call to make(§Making slies、maps、and chanels)When compring two values of chanel type、the chanel value types must be comptible but the chanel direct.チャンネルはmapと同じで、もし二つの変数が同じmakeによって呼び出されて作成されたら、それらは同じです。二つのチャネルの値を比較する時、チャンネルの値は方向に適合されますが、Intervance falutervaceは無視されます。y be compred if they have comptible static types.They will be equal only the y have the same dynamic type and the undering values are equal.インターフェースは互換性のある静的インターフェースと比較できます。もしそれらが同じダイナミックタイプがあれば、それらの値は同じです。 コメントを見る