{"id":2737,"date":"2018-05-01T08:32:31","date_gmt":"2018-05-01T00:32:31","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=2737"},"modified":"2018-05-01T08:32:31","modified_gmt":"2018-05-01T00:32:31","slug":"java-util-observable%ef%bc%88%e8%a7%82%e5%af%9f%e8%80%85%e6%a8%a1%e5%bc%8f%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=2737","title":{"rendered":"java.util.Observable\uff08\u89c2\u5bdf\u8005\u6a21\u5f0f\uff09"},"content":{"rendered":"<p>\n\t\u5728Java\u4e2d\u901a\u8fc7Observable\u7c7b\u548cObserver\u63a5\u53e3\u5b9e\u73b0\u4e86\u89c2\u5bdf\u8005\u6a21\u5f0f\u3002Observer\u5bf9\u8c61\u662f\u89c2\u5bdf\u8005\uff0cObservable\u5bf9\u8c61\u662f\u88ab\u89c2\u5bdf\u8005\u3002\n<\/p>\n<p>\n\t[1]\u521b\u5efa\u88ab\u89c2\u5bdf\u8005\u7c7b\uff0c\u5b83\u7ee7\u627f\u81eajava.util.Observable\u7c7b\uff1b<br \/>\n\t[2]\u521b\u5efa\u89c2\u5bdf\u8005\u7c7b\uff0c\u5b83\u5b9e\u73b0java.util.Observer\u63a5\u53e3\uff1b<br \/>\n\t&nbsp; &nbsp; &nbsp; &nbsp;\u5b9e\u73b0Observer\u63a5\u53e3\u7684\u552f\u4e00\u65b9\u6cd5update<br \/>\n\t&nbsp; &nbsp; &nbsp; &nbsp;void update(Observable o, Object arg);<br \/>\n\t&nbsp; &nbsp; &nbsp; &nbsp;\u5f62\u53c2Object arg\uff0c\u5bf9\u5e94\u4e00\u4e2a\u7531notifyObservers(Object arg);\u4f20\u9012\u6765\u7684\u53c2\u6570\uff0c\u5f53\u6267\u884c\u7684\u662fnotifyObservers();<br \/>\n\t[3]\u5bf9\u4e8e\u88ab\u89c2\u5bdf\u8005\u7c7b\uff0c\u6dfb\u52a0\u5b83\u7684\u89c2\u5bdf\u8005\uff1a<br \/>\n\t&nbsp; &nbsp; &nbsp; &nbsp;voidaddObserver(Observer o)<br \/>\n\t&nbsp; &nbsp; &nbsp; &nbsp;addObserver()\u65b9\u6cd5\u628a\u89c2\u5bdf\u8005\u5bf9\u8c61\u6dfb\u52a0\u5230\u89c2\u5bdf\u8005\u5bf9\u8c61\u5217\u8868\u4e2d\u3002<br \/>\n\t\u5f53\u88ab\u89c2\u5bdf\u4e8b\u4ef6\u53d1\u751f\u65f6\uff0c\u6267\u884c\uff1a<br \/>\n\tsetChanged();<br \/>\n\tnotifyObservers();<br \/>\n\tsetChange()\u65b9\u6cd5\u7528\u6765\u8bbe\u7f6e\u4e00\u4e2a\u5185\u90e8\u6807\u5fd7\u4f4d\u6ce8\u660e\u6570\u636e\u53d1\u751f\u4e86\u53d8\u5316\uff1b<br \/>\n\tnotifyObservers()\u65b9\u6cd5\u4f1a\u53bb\u8c03\u7528\u89c2\u5bdf\u8005\u5bf9\u8c61\u5217\u8868\u4e2d\u6240\u6709\u7684Observer\u7684update()\u65b9\u6cd5\uff0c\u901a\u77e5\u5b83\u4eec\u6570\u636e\u53d1\u751f\u4e86\u53d8\u5316\u3002<br \/>\n\t\u53ea\u6709\u5728setChange()\u88ab\u8c03\u7528\u540e\uff0cnotifyObservers()\u624d\u4f1a\u53bb\u8c03\u7528update()\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=2737\">java.util.Observable\uff08\u89c2\u5bdf\u8005\u6a21\u5f0f\uff09<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u5728Java\u4e2d\u901a\u8fc7Observable\u7c7b\u548cObserver\u63a5\u53e3\u5b9e\u73b0\u4e86\u89c2\u5bdf\u8005\u6a21\u5f0f\u3002Observer\u5bf9\u8c61\u662f\u89c2\u5bdf\u8005\uff0cO [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[1240,69,391,216,1143],"class_list":["post-2737","post","type-post","status-publish","format-standard","hentry","category-java","tag-blink","tag-java","tag-mysql","tag-216","tag-1143"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2737","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2737"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2737\/revisions"}],"predecessor-version":[{"id":2738,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2737\/revisions\/2738"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}