列舉模擬較和工具方法

2021-09-23 18:13:02 字數 1077 閱讀 5644

目錄

列舉比較

工具方法

測試**

可以使用equals 也可以使用==

public enum cardtype 

/*** code 轉成列舉物件

* @param code

* @return

*/public static cardtype toenum(integer code)

}return null;

}public static string getnamebyvalue(integer value)

}return "";

}/**

* 檢查列舉是否安全

* @param value

* @return

*/public static boolean chkisselfenum(integer value)

}return boolean.false;

}public integer getvalue()

public string getname()

}

system.out.println("列舉使用==:"+(cardtype.sfz==cardtype.sfz));

system.out.println("列舉使用equals:"+(cardtype.sfz.equals(cardtype.sfz)));

列舉使用==:true

列舉使用equals:true

列舉內部工具方法傳值要和普通方法一樣看待

system.out.println("列舉值integer和string:"+(enumcredittype.sfz.getvalue().equals(101+"")));

system.out.println("列舉toenum引數傳string:"+(enumcreditstatus.toenum(1)));

列舉值integer和string:false

列舉和模擬

列舉,或者說暴力列舉,聽起來好像比較簡單,只要把所有可能都列舉一遍並從中找出正確答案即可,但是列舉有乙個弊端 容易超時,所以必須想辦法優化。所以列舉不僅不必其他類別題目簡單,優化這一點可能難度還會超過其他題目。下面是我在oj提交過的兩個題目 1 火柴棒 題目描述不在說了 該題有兩個要點 1.a和b不...

Python中與模擬較相關的魔術方法

class square object 比較長方形的面積大小 def init self,width,height self.width width self.height height def res area self return self.width self.height def eq s...

Java包裝模擬較和包裝類底層快取陣列

關於包裝類的比較問題,我們先看以下 integer i1 100 integer i2 100 integer i3 200 integer i4 200 system.out.println i1 i2 true system.out.println i3 i4 false double d1 1...