当前位置:网站首页>(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,自然,就不存在以上的不爽了。这样会很清晰!
边栏推荐
- Serial port experiment - simple data sending and receiving
- Self awakening from a 30-year-old female programmer
- JVM garbage collection detailed learning notes (II)
- C语言指针(习题篇)
- Entity of cesium data visualization (Part 1)
- Serializer & modelserializer of DRF serialization and deserialization
- Druid monitoring - Introduction to JMX usage and principle
- Confitest of fixture py
- Interpretation of MySQL optimization principle
- PMP examination experience sharing
猜你喜欢

Synchronized underlying principle, volatile keyword analysis

Two schemes of unit test

Summary of PMP learning materials

C language for calculating the product of two matrices

NVIC interrupt priority management

Postman data driven

H3C VXLAN配置

Storage of data in memory

【Istio Network CRD VirtualService、Envoyfilter】

PMP certificate preparation experience sharing
随机推荐
Count the number of words in the string c language
[chaosblade: node CPU load, node network delay, node network packet loss, node domain name access exception]
PMP Exam Preparation experience systematically improve project management knowledge through learning
Skill review of test engineer before interview
Test Engineer Interview Questions 2022
How to count the number of project code lines
Count the number of words C language
What is the rating of Huishang futures company? Is it safe to open an account? I want to open an account, OK?
C language pointer (exercises)
Output all composite numbers between 6 and 1000
Simulation volume leetcode [general] 1609 Parity tree
The essence of high availability
Led analog and digital dimming
C语言指针(特别篇)
C语言指针(下篇)
NVIC interrupt priority management
Entity of cesium data visualization (Part 1)
C语言指针(习题篇)
C language pointer (Part 2)
What are the conditions for applying for NPDP?