当前位置:网站首页>(3/8)枚举的不当用法 之 方法参数(二)
(3/8)枚举的不当用法 之 方法参数(二)
2022-07-07 06:34:00 【51CTO】
继续讲枚举的使用。本文举例说明方法的参数不用枚举所带来的蹩脚之处。
【先上代码】
先看如下方法:
程序里对这个方法的调用:
如下是RefundStsEnum枚举类:
【重构方式】
上面方法中的String变量rfdSts,在程序里有定义对应的枚举类型RefundStsEnum。
本例是典型的枚举使用不当。症结在于将方法参数rfdSts定义成了String,这导致了两点不爽:
- 该方法内部,如第一行,打日志时,先调用枚举RefundStsEnum的getBySts(),将rfdSts所存的RefundStsEnum的sts转换成枚举RefundStsEnum,然后,获取它的desc。
- 调用该方法传的参数是RefundStsEnum.getSts()
正确的实现方式是:将方法参数rfdSts定义为枚举类型RefundStsEnum,自然,就不存在以上的不爽了。这样会很清晰!
边栏推荐
- Original collection of hardware bear (updated on May 2022)
- Simulation volume leetcode [general] 1557 The minimum number of points that can reach all points
- [chaosblade: node disk filling, killing the specified process on the node, suspending the specified process on the node]
- Two schemes of unit test
- 硬件大熊原创合集(2022/06更新)
- OpenGL三维图形绘制
- Postman data driven
- Selenium mouse sliding operation event
- [chaosblade: node CPU load, node network delay, node network packet loss, node domain name access exception]
- Some pit avoidance guidelines for using Huawei ECS
猜你喜欢

数据在内存中的存储

Locust performance test 2 (interface request)

Unityshader introduction essentials personal summary -- Basic chapter (I)

PMP Exam Preparation experience systematically improve project management knowledge through learning

Upgrade Alibaba cloud RDS (relational database service) instance to com mysql. jdbc. exceptions. Troubleshooting of jdbc4.communicationsexception

【istio简介、架构、组件】

STM32的时钟系统

端口复用和重映像

Locust performance test 4 (custom load Policy)

Output a spiral matrix C language
随机推荐
Upgrade Alibaba cloud RDS (relational database service) instance to com mysql. jdbc. exceptions. Troubleshooting of jdbc4.communicationsexception
Serializer & modelserializer of DRF serialization and deserialization
Analysis of Hessian serialization principle
【SVN】SVN是什么?怎么使用?
Golang etcdv3 reports an error. The attribute in grpc does not exist
寄存器地址名映射
徽商期货公司评级是多少?开户安全吗?我想开户,可以吗?
OpenGL 3D graphics rendering
How to pass the PMP Exam in a short time?
【istio简介、架构、组件】
Serial port experiment - simple data sending and receiving
Count the number of words C language
模拟卷Leetcode【普通】1557. 可以到达所有点的最少点数目
模拟卷Leetcode【普通】1567. 乘积为正数的最长子数组长度
Self awakening from a 30-year-old female programmer
C语言指针(习题篇)
端口复用和重映像
OpenGL三维图形绘制
NVIC interrupt priority management
Postman interface test (II. Set global variables \ sets)