当前位置:网站首页>(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,自然,就不存在以上的不爽了。这样会很清晰!
边栏推荐
- C language pointer (Part 2)
- 2020 year end summary
- Test Engineer Interview Questions 2022
- Interview question: general layout and wiring principles of high-speed PCB
- C语言指针(习题篇)
- Simulation volume leetcode [general] 1706 Where does the ball meet
- Expérience de port série - simple réception et réception de données
- External interrupt to realize key experiment
- Three updates to build applications for different types of devices | 2022 i/o key review
- Original collection of hardware bear (updated on May 2022)
猜你喜欢
MySQL master-slave delay solution
Systick tick timer
Upgrade Alibaba cloud RDS (relational database service) instance to com mysql. jdbc. exceptions. Troubleshooting of jdbc4.communicationsexception
Systick滴答定时器
Why is access to the external network prohibited for internal services of the company?
Do you have any certificates with high gold content?
PMP Exam details after the release of the new exam outline
2022-06-30 unity core 8 - model import
Two schemes of unit test
Druid monitoring - Introduction to JMX usage and principle
随机推荐
Hard core sharing: a common toolkit for hardware engineers
Skill review of test engineer before interview
STM32的时钟系统
Output a spiral matrix C language
寄存器地址名映射
2022-07-06 Unity核心9——3D动画
On December 8th, 2020, the memory of marketing MRC application suddenly increased, resulting in system oom
数据在内存中的存储
Original collection of hardware bear (updated on May 2022)
Cmake command line use
Register address name mapping
MySql数据库-事务-学习笔记
Serial port experiment - simple data sending and receiving
[chaosblade: delete pod according to the tag, pod domain name access exception scenario, pod file system i/o failure scenario]
Common short chain design methods
OpenGL 3D graphics rendering
C语言指针(习题篇)
What are the conditions for applying for NPDP?
C语言指针(上篇)
Record of structured interview