作者godfat (godfat 真常)
看板java
标题Re: [问题] 在类别中生成一个自己的实例(static用 …
时间Fri Jul 13 10:45:46 2007
※ 引述《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://webptt.com/cn.aspx?n=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