Re: [問題] 在類別中生成一個自己的實例(static用 …
※ 引述《Ronamtis (Tis)》之銘言:
: 我的問題是:在 AccountDB 類別產生了一個 AccountDB 自己的實例,這到底是怎
: 麼回事呢?是否因為 onlyInstance 被宣告成 static,只有在類別第一次被呼叫時
: 會產生出來,所以不會發生無窮迴圈的問題?
說到這,我倒是真的幹過無窮產生的問題﹍不過這是題外話
你可以把 static 想成 class, 所以 static method => class method
static field => class field
class 當然只有一個,所以沒有問題,這是你的 class 去存取一個 instance,
不是 class 存取 class 也不是 instance 存取 instance.
個人認為這是 C 的禍害 :o
讓人困惑的 static 多重意義,java 早就沒有最早的 static 了
: 沒用實體變數的 method (或物件?)不會佔用 heap 的空間,但是怎麼執行的呀?
: 觀念很不清楚,不知道有沒有善心人士可以指點一下迷津...謝謝 :)
記憶體不是只有 heap 啊 :o
--
#!/usr/bin/ruby [露比] /Programming (Kn|N)ight/ 看板《Ruby》
# if a dog nailed extra legs that http://www.ptt.cc/bbs/Ruby/index.html
# walks like an octopus, and Welcome ~Ruby@ptt~
# talks like an octopus, then ◢█◣ http://www.ruby-lang.org/
# we are happy to treat it as █ http://www.ruby-doc.org/
# if it were an octopus. ◥ ◤ http://www.rubyforge.org/
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.218.90.242
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 2 之 8 篇):