在Python中的一个,您可以:检查是否值是很多常量
if error_code in (1213,1205,1317,2006,2013):
...
你怎么能做到简洁的同类检查 - 如果看到一个int是众多选择之一 - 在Java中?
更新:我采取的解决办法:
private static final Set<Integer> MySQLRetryCodes =
Collections.unmodifiableSet(new HashSet<Integer>(
Arrays.asList(
1205, // lock timeout
1213, // deadlock
1317,2006,2013 // variations on losing connection to server
)));
再后来:
if(MySQLRetryCodes.contains(sqlError.getErrorCode()) {
...
我喜欢这种方法;小错字:数组。 asList(... –
Will
编译器会自动确定类型,并且''不是明确需要的。 –
Vikdor
好吧,我只需要输入就可以让Eclipse高兴起来 –
Will