有没有办法使枚举值大于2746?

时间:2019-06-05 08:58:15

标签: java enums

我正在使用ENUM保存密钥,这些密钥使我可以从数据库中获取特定消息。显然,ENUMs的限制为2746,而我的新代码将其限制为2751,所以我遇到了编译错误。 有什么办法可以扩展这个ENUM吗?还是我需要使用一个新的新值?

1 个答案:

答案 0 :(得分:-1)

不应将枚举用于如此大量的元素,在这种情况下,我建议使用简单的整数常量,它们最多可以有20亿个可能性,如果很小,那么请尝试使用,只要它们可以存储更多整数。

例如:

function S2 = q56456298()
%% Generate a dataset:
ROWS = 128;
isUnwanted = randn(ROWS,1) > 0 ;
S = repmat(struct('Name',[], 'Data', []), 1, ROWS);
for ind1 = 1:ROWS
  if isUnwanted(ind1)
    S(ind1).Name = sprintf('Unwanted%u', ind1);
  else
    S(ind1).Name = sprintf('Useful%u', ind1);
  end
  S(ind1).Data = array2table(rand(randi(200),4));
end

%% Remove all "Unwanted fields"
names = string({S.Name}).'; % Here we collect all names, and make it a string array.

toRemove = "Unwanted" + (1:ROWS).'; % This simulates your "sn" array.
[~, idxToDelete] = ismember(toRemove, names);
S2 = S(~idxToDelete); % The result only contains "Useful" rows.
相关问题