枚举值是什么类型?

时间:2019-01-27 09:21:00

标签: java collections enums

我是Java的新手,似乎无法理解我的方法返回的值。我认为应该是List,但事实并非如此。该方法正在做的只是从我得到的枚举类中获取所有值。这是代码:

public static List getRandomSquare() {
  // What should replace "List"?
  Square[] squareTypes = Square.values();
  return squareTypes;
}

在这种情况下应该用什么来代替List

1 个答案:

答案 0 :(得分:2)

按照上面发布的代码,返回类型应为$subs = Get-AzureRmSubscription # Resource start\stop role $role = Get-AzureRmRoleDefinition "Virtual Machine Contributor" $role.Id = $null $role.Name = "Resource Start/Stop (Scheduled)" $role.Description = "Can read\start\stop VMs" $role.Actions.Clear() $role.Actions.Add("Microsoft.Compute/virtualMachines/deallocate/action") $role.Actions.Add("Microsoft.Compute/virtualMachines/read") $role.Actions.Add("Microsoft.Compute/virtualMachines/restart/action") $role.Actions.Add("Microsoft.Compute/virtualMachines/start/action") $role.AssignableScopes.Clear() $subs | ForEach-Object { $scope = "/subscriptions/{0}" -f $_.Id $role.AssignableScopes.Add($scope) } $def = New-AzureRmRoleDefinition -Role $role ,即Square[]对象的数组:

Square

如果您想返回public static Square[] getRandomSquare() { Square[] squareTypes = Square.values(); return squareTypes; } 对象的列表,则我们使用Square

Arrays.asList