我在引擎盖下查看EnumSet.allOf它看起来非常有效,特别是对于少于64个值的枚举.
基本上所有集合共享所有可能的枚举值的单个数组,并且唯一的另一条信息是位掩码,如果allOf是一次设置的话.
另一方面,Enum.values()似乎有点黑魔法.此外,它返回一个数组,而不是一个集合,因此在许多情况下,它必须使用Arrays.asList()进行修饰,以便在任何需要收集的地方使用.
那么,应该EnumSet.allOf更优选Enum.values吗?
更具体地说,for应该使用哪种形式的迭代器:
for ( final MyEnum val: MyEnum.values( ) );
Run Code Online (Sandbox Code Playgroud)
要么
for ( final MyEnum val: EnumSet.allOf( MyEnum.class ) );
Run Code Online (Sandbox Code Playgroud) 我需要建议是这个解决方案可以接受并且不会导致溢出,我更新了使用AsyncTask读取的数据,在AsyncTask完成后我需要一次又一次地更新.这个解决方案是否可接受且安全
private class DownloadFilesTask extends AsyncTask<URL,Integer,com.ring_view.www.json.System> {
@Override
protected com.ring_view.www.json.System doInBackground(URL... params) {
int count = params.length;
URL temp=params[0];
System system=null;
try {
system = Communicator.getSystem(temp);
} catch (LoggingConnectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONParsingErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return system;
}
protected void onProgressUpdate(Integer... progress) {
//setProgressPercent(progress[0]);
}
protected void onPostExecute(com.ring_view.www.json.System result) {
txtWorkAllowedValue.setText(result.work_allowed);
try {
new DownloadFilesTask().execute(new URL("http://test/status-system.json"));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block …Run Code Online (Sandbox Code Playgroud)