Thread Rating:
  • 478 Vote(s) - 2.82 Average
  • 1
  • 2
  • 3
  • 4
  • 5
#t , any , Type の違いは?
09-17-2013, 08:05 PM, (This post was last modified: 10-22-2013, 09:10 AM by umemura.)
#4
RE: #t , any , Type の違いは?
heavybugtrackerさん、wbardwellさん、ありがとうございます。

なるほど。
Template の「t」なのですね。
また、この型宣言は、クラス宣言部でしか使えない、という認識です

any 型ではなく、インスタンス時に型が決まるので、
プログラミング中に、フィールドやメソッドのオートコンプリートが表示されるわけですね。

Type と ClassType も、意味は若干異なり、前者はすべての型、後者はクラスの型をあらわす、という理解です。

勉強になりました。

Code:
{define-class public {CustomClass-of t:Type}
  field data:t
  {constructor public {default data:t}
    set self.data = data
  }
}

{define-class public {CustomClassNull-of t:Type}
  field data:#t
  {constructor public {default data:#t}
    set self.data = data
  }
}

{define-class public CustomClass
  field data:any
  {constructor public {default data:any}
    set self.data = data
  }
}

{def a = {{CustomClass-of String} "String"}} ||<- null を指定できない
{value {type-of a.data}}

{def c = {{CustomClassNull-of String} null}} ||null指定可能
{value {type-of c.data}}

{def b = {CustomClass "String"}}
{value {type-of b.data}}

{do
    let str:String = ""
    set str = a.data  || キャスト必要なし
    set str = {non-null c.data} || nullable の判断
    set str =  b.data asa String || 明示的なキャストが必要

}


Messages In This Thread
#t , any , Type の違いは? - by umemura - 09-10-2013, 06:02 PM
RE: #t , any , Type の違いは? - by umemura - 09-17-2013, 08:05 PM

Possibly Related Threads...
Thread Author Replies Views Last Post
  type-switch で Array-of 、HashTable-of を判別したい umemura 2 3,824 12-28-2012, 01:39 PM
Last Post: wbardwell
Forum Jump:


Users browsing this thread:
1 Guest(s)

MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1017 - Can't find file: 'mybb_threadviews' (errno: 2)
Query:
INSERT INTO mybb_threadviews (tid) VALUES('966')