当前位置:网站首页>(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,自然,就不存在以上的不爽了。这样会很清晰!
边栏推荐
- MySql数据库-索引-学习笔记
- 5A summary: seven stages of PMP learning
- Digital triangle model acwing 1027 Grid access
- Reading notes of pyramid principle
- Regularly modify the system time of the computer
- systemd
- 2022-06-30 Unity核心8——模型导入
- Mysql数据库-锁-学习笔记
- 【Istio Network CRD VirtualService、Envoyfilter】
- Unity Shader入门精要初级篇(一)-- 基础光照笔记
猜你喜欢

How long does the PMP usually need to prepare for the exam in advance?

C语言指针(特别篇)

Register address name mapping

Serial port experiment - simple data sending and receiving

Entity of cesium data visualization (Part 1)

Expérience de port série - simple réception et réception de données

Locust performance test 5 (analysis)

C language pointer (special article)

Confitest of fixture py

Cesium does not support 4490 problem solution and cesium modified source code packaging scheme
随机推荐
C语言指针(上篇)
2022-06-30 unity core 8 - model import
Simulation volume leetcode [general] 1557 The minimum number of points that can reach all points
OpenGL三维图形绘制
Selenium mouse sliding operation event
Count the number of words in the string c language
External interrupt to realize key experiment
Digital triangle model acwing 275 Pass a note
2020 year end summary
Vagrant failed to mount directory mount: unknown filesystem type 'vboxsf'
Cmake command line use
JVM garbage collection detailed learning notes (II)
When inputting an expression in the input box, an error is reported: incorrect string value:'\xf0\x9f... ' for column 'XXX' at row 1
[chaosblade: node disk filling, killing the specified process on the node, suspending the specified process on the node]
Confitest of fixture py
2021 year end summary
5A summary: seven stages of PMP learning
Postman data driven
Several common database connection methods
OpenGL帧缓冲