⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch04s02.html

📁 优秀的java程序开发软件方式与方法,对大家开发程序的时候有指导性帮助
💻 HTML
📖 第 1 页 / 共 2 页
字号:
        }                switch (count) {        case 0:            System.out.println("Parent: 1");            s = null;        case 1:            try {                child(1, s);            } catch (RecordStackException e) {                parentRecordStack(e.getRuntimeStack(), 1);            }            s = null;        case 2:            System.out.println("Parent: 2");            s = null;        case 3:            try {                child(2, s);            } catch (RecordStackException e) {                parentRecordStack(e.getRuntimeStack(), 3);            }            s = null;        case 4:            System.out.println("Parent: 3");            s = null;        }    }        static void childRecordStack(RuntimeStack s, int c, int i) {        s.pushCount(c);        s.pushInt(i);        throw new RecordStackException(s);    }        static void child(int i, RuntimeStack s) {        int count = 0;        if (s != null) {            count = s.popCount();            i = s.popInt();        }        switch (count) {        case 0:            System.out.println("Child: i = " + i);            s = null;        case 1:            if (i == 2)                childRecordStack(new RuntimeStack(), 2, i);        case 2:            System.out.println("Child exits.");            s = null;        }    }    public static void main(String[] args) {        try {            parent(null);        } catch (RecordStackException e) {            System.out.println("Record stack exception caught.");            RuntimeStack s = e.getRuntimeStack();            parent((RuntimeStack) s.clone());            parent((RuntimeStack) s.clone());            parent((RuntimeStack) s.clone());        }    }}</pre><p>&#19978;&#38754;&#36825;&#27573;&#20195;&#30721;&#30340;&#36755;&#20986;&#22914;&#19979;&#12290;&#27880;&#24847;&#21040;Record stack exception caught&#20043;&#21518;&#30340;&#36755;&#20986;&#37325;&#22797;&#20102;&#19977;&#36941;&#12290;</p><pre class="screen">Parent: 1Child: i = 1Child exits.Parent: 2Child: i = 2Record stack exception caught.Child exits.Parent: 3Child exits.Parent: 3Child exits.Parent: 3</pre><p>&#25105;&#20204;&#26469;&#30475;&#30475;&#36825;&#27573;&#22855;&#24618;&#30340;&#20195;&#30721;&#12290;&#25105;&#20204;&#30340;&#20219;&#21153;&#19968;&#26159;&#35201;&#33021;&#22815;&#25226;stack&#20445;&#23384;&#22312;&#19968;&#20010;RuntimeStack&#23545;&#35937;&#20013;&#65292;&#20108;&#26159;&#35201;&#33021;&#22815;&#24674;&#22797;&#19968;&#20010;&#32473;&#23450;&#30340;RuntimeStack&#23545;&#35937;&#20013;&#30340;&#29366;&#24577;&#12290;&#27880;&#24847;&#21040;&#25105;&#20204;&#22312;RuntimeStack&#20013;&#32473;&#20102;count&#21644;&#26412;&#22320;&#21464;&#37327;&#20004;&#20010;&#19981;&#21516;&#30340;stack&#12290;&#36825;&#20854;&#23454;&#24182;&#19981;&#24517;&#35201;&#65292;&#19981;&#36807;&#33267;&#23569;&#25105;&#35273;&#24471;&#36825;&#26679;&#27604;&#36739;&#28165;&#26970;&#12290;</p><p>&#25105;&#20204;&#20570;&#30340;&#20027;&#35201;&#21464;&#21270;&#22312;DuplicateStack&#31867;&#30340;parent()&#21644;child()&#20004;&#20010;&#20989;&#25968;&#65292;&#36825;&#20123;&#21464;&#21270;&#20855;&#20307;&#20026;&#65306;</p><div class="orderedlist"><ol type="1"><li><p>&#20004;&#20010;&#20989;&#25968;&#37117;&#22810;&#25509;&#21463;&#19968;&#20010;RuntimeStack&#21442;&#25968;&#12290;&#20989;&#25968;&#30340;&#24320;&#22836;&#20415;&#26159;&#26816;&#26597;&#35813;&#21442;&#25968;&#65292;&#24403;RuntimeStack&#26159;null&#26102;&#65292;&#20004;&#20010;&#20989;&#25968;&#37117;&#20174;&#22836;&#25191;&#34892;&#36215;&#65307;&#21542;&#21017;&#65292;&#20989;&#25968;&#20250;&#20174;&#20013;&#33719;&#21462;&#26412;&#22320;&#21464;&#37327;&#30340;&#20540;&#65288;&#20363;&#22914;child()&#20013;&#30340;i&#65289;&#65292;&#24182;&#36339;&#21040;RuntimeStack&#20013;&#25351;&#23450;&#30340;count&#22788;&#12290;&#36825;&#20123;&#25805;&#20316;&#20351;&#20989;&#25968;&#33021;&#22815;&#24674;&#22797;&#21040;RuntimeStack&#25351;&#26126;&#30340;&#29366;&#24577;&#12290;</p></li><li><p>&#20004;&#20010;&#20989;&#25968;&#30340;&#20027;&#20307;&#37096;&#20998;&#37117;&#21464;&#25104;&#20102;&#19968;&#20010;&#22823;switch&#65292;&#27599;&#20010;&#35821;&#21477;&#21069;&#22810;&#20102;&#19968;&#20010;case&#12290;&#36825;&#26159;&#22240;&#20026;&#24403;&#26377;RuntimeStack&#21442;&#25968;&#26102;&#25105;&#20204;&#38656;&#35201;&#33021;&#22815;&#36339;&#21040;Stack&#25351;&#23450;&#30340;&#20219;&#20309;&#35821;&#21477;&#65292;Java&#28304;&#20195;&#30721;&#37324;&#30340;&#20570;&#27861;&#26159;&#20174;Stack&#20013;&#35835;&#21462;count&#65292;&#28982;&#21518;switch&#21040;count&#25152;&#25351;&#23450;&#30340;&#35821;&#21477;&#12290;&#22914;&#26524;&#25105;&#20204;&#22312;bytecode&#19978;&#36827;&#34892;&#25805;&#20316;&#65292;&#37027;&#20040;&#25105;&#20204;&#23601;&#19981;&#38656;&#35201;&#36825;&#20010;switch&#20102;&#65292;&#22240;&#20026;&#25105;&#20204;&#21487;&#20197;&#30452;&#25509;goto&#21040;&#24819;&#35201;&#21040;&#30340;&#22320;&#26041;&#12290;</p></li><li><p>&#27599;&#20010;&#21487;&#33021;&#20351;&#29992;continuation&#30340;&#20989;&#25968;&#35843;&#29992;&#37117;&#22312;&#19968;&#20010;try/catch&#32467;&#26500;&#20013;&#65292;catch&#20250;&#35843;&#29992;&#19968;&#20010;&#23545;&#24212;&#30340;XXXRecordStack&#20989;&#25968;&#12290;&#20854;&#25805;&#20316;&#26159;&#32426;&#24405;&#19979;&#20989;&#25968;&#24403;&#21069;&#30340;&#29366;&#24577;&#65292;&#21253;&#25324;&#27491;&#22312;&#25191;&#34892;&#30340;&#35821;&#21477;&#32534;&#21495;&#21644;&#26412;&#22320;&#21464;&#37327;&#30340;&#20540;&#65292;&#28982;&#21518;&#37325;&#26032;&#25243;&#20986;RecordStackException&#12290;&#36825;&#26679;&#19968;&#23618;&#19968;&#23618;&#25243;&#19979;&#21435;&#65292;&#27599;&#20010;&#20989;&#25968;&#23601;&#37117;&#33021;&#32426;&#24405;&#19979;&#33258;&#24049;&#30340;&#29366;&#24577;&#24182;&#25918;&#21040;RecordStackException&#30340;RuntimeStack&#20013;&#21435;&#12290;&#19979;&#38754;&#26159;&#30456;&#20851;&#30340;&#26680;&#24515;&#20195;&#30721;&#65306;</p><pre class="programlisting">static void childRecordStack(RuntimeStack s, int c, int i) {    s.pushCount(c);    s.pushInt(i);    throw new RecordStackException(s);}</pre></li></ol></div><p>&#26377;&#20102;&#32426;&#24405;&#29366;&#24577;&#21644;&#24674;&#22797;&#29366;&#24577;&#30340;&#33021;&#21147;&#65292;&#25105;&#20204;&#23601;&#21487;&#20197;&#36827;&#34892;&#25105;&#20204;&#30340;&#8220;&#40657;&#33394;&#39764;&#27861;&#8221;&#20102;&#12290;&#25105;&#20204;&#35201;&#32426;&#24405;&#19979;&#24403;&#21069;Stack&#26102;&#65292;&#21482;&#39035;&#35843;&#29992;XXXRecordStack&#20989;&#25968;&#32426;&#24405;&#19979;&#26412;&#20989;&#25968;&#24403;&#21069;&#29366;&#24577;&#28982;&#21518;&#25243;&#20986;RecordStackException&#23601;&#21487;&#20197;&#20102;&#12290;&#20989;&#25968;main()&#20250;&#25130;&#33719;&#35813;RecordStackException&#24182;&#21462;&#20986;&#20854;&#20013;&#30340;Stack&#12290;&#36825;&#26102;&#65292;main()&#20989;&#25968;&#23601;&#21487;&#20197;&#20219;&#24847;&#22320;&#22797;&#21046;&#21644;&#35843;&#29992;&#35813;Stack&#20102;&#12290;&#19978;&#38754;&#30340;&#20363;&#23376;&#35843;&#29992;&#20102;&#19977;&#36941;Stack&#65292;&#25152;&#20197;&#25105;&#20204;&#20250;&#30475;&#21040;&#19977;&#20010;&#8220;Child exits. Parent: 3&#8221;&#12290;&#25105;&#20204;&#30475;&#21040;&#36825;&#37324;&#30340;RuntimeStack&#24050;&#32463;&#38750;&#24120;&#25509;&#36817;&#19982;&#19968;&#20010;&#23436;&#25972;&#30340;continuation&#20102;&#12290;</p><p>&#25105;&#20204;&#24403;&#28982;&#19981;&#21487;&#33021;&#20687;&#19978;&#38754;&#37027;&#26679;&#20889;&#20195;&#30721;&#65292;&#19981;&#36807;&#25226;&#26222;&#36890;&#30340;&#20195;&#30721;&#36716;&#25442;&#25104;&#19978;&#38754;&#26684;&#24335;&#30340;&#36807;&#31243;&#30456;&#24403;&#27515;&#26495;&#65292;&#25152;&#20197;&#25105;&#20204;&#21487;&#20197;&#29992;&#24037;&#20855;&#33258;&#21160;&#23436;&#25104;&#12290;&#24403;&#28982;&#65292;&#20195;&#30721;&#30340;&#22823;&#23567;&#21644;&#36895;&#24230;&#37117;&#20250;&#36828;&#19981;&#22914;&#26222;&#36890;&#30340;Java&#12290;</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch04s01.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="ch04.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="ch04s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">1.&nbsp;Continuation&#30340;&#24120;&#35268;&#23454;&#29616;&#26041;&#27861;&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;3.&nbsp;&#22312;Java&#19978;&#23454;&#29616;Continuation&#65306;&#22522;&#20110;heap&#27861;</td></tr></table></div></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -