我在我的 groovy 脚本中使用 AWS api:
new AmazonDynamoDBClientBuilder ()
.withRegion(Regions.SA_EAST_1)
.build()
我希望能够将区域作为用户参数传递给脚本,但 Regions 是一个枚举。如何将区域(如“SA_EAST_1”或“CN_NORTH_1”)作为字符串传递?我可以拥有自己的映射来将字符串值转换为枚举值,但这看起来真的很愚蠢。
最佳答案
// convert the enum value to a string using name
String name = Region.SA_EAST_1.name();
// convert the string to a enum value
Region value = Region.valueOf(name);
关于java - 使用变量的值作为枚举值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47382381/