久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

Java程序的編碼規范(3)

瀏覽:115日期:2024-07-03 09:26:15
內容: Java程序的編碼規范(3)作者:李小敏 本文選自:IBM DW中國 2002年08月21日 ● 構造函數 接下來是構造函數,它應該用遞增的方式寫(比如:參數多的寫在后面)。 訪問類型 ('public', 'private' 等.) 和 任何 'static', 'final' 或 'synchronized' 應該在一行中,并且方法和參數另寫一行,這樣可以使方法和參數更易讀。 publicCounterSet(int size){ this.size = size;} ● 克隆方法 如果這個類是可以被克隆的,那么下一步就是 clone 方法: publicObject clone() { try { CounterSet obj = (CounterSet)super.clone(); obj.packets = (int[])packets.clone(); obj.size = size; return obj; }catch(CloneNotSupportedException e) { throw new InternalError('Unexpected CloneNotSUpportedException: ' + e.getMessage()); }} ● 類方法 下面開始寫類的方法: /** * Set the packet counters * (such as when restoring from a database) */protected finalvoid setArray(int[] r1, int[] r2, int[] r3, int[] r4) throws IllegalArgumentException{ // // Ensure the arrays are of equal size // if (r1.length != r2.length || r1.length != r3.length || r1.length != r4.length) throw new IllegalArgumentException('Arrays must be of the same size'); System.arraycopy(r1, 0, r3, 0, r1.length); System.arraycopy(r2, 0, r4, 0, r1.length);} ● toString 方法 無論如何,每一個類都應該定義 toString 方法: publicString toString() { String retval = 'CounterSet: '; for (int i = 0; i
標簽: Java
相關文章:
主站蜘蛛池模板: 四平市| 海盐县| 万州区| 卓资县| 石城县| 阜平县| 福鼎市| 永丰县| 牟定县| 台湾省| 沙坪坝区| 江北区| 竹山县| 乌兰察布市| 靖宇县| 苍山县| 确山县| 工布江达县| 香格里拉县| 灵寿县| 安西县| 安塞县| 南岸区| 吉木萨尔县| 武乡县| 红河县| 莱西市| 林西县| 大城县| 郧西县| 昂仁县| 都昌县| 北京市| 罗田县| 名山县| 麦盖提县| 大石桥市| 淮阳县| 清水河县| 焉耆| 班戈县|