Comments (5)
不去实现这个接口那就没有这问题了吧
from p3c.
@chenxuyuan2016 对,不实现当然没问题,我的问题是该不该这样使用
from p3c.
@Tneciv interface和@interface中定义的常量,是自带public static final 修饰的,其实和正常的class public static final 是一致的,我个人觉得正确的使用它和正常的常量类是一致的,而且感觉会少些代码何乐而不为呢。该不该使用它并不是由规范来决定的,是看个人的想法,如果你觉得这样做不安全可以不实用,如果你觉得这样做方便并且能够让他安全使用,不必去纠结。
from p3c.
@chenxuyuan2016 是应该结合使用场景选择,既然说到这里了就顺便引用下我之前看到一篇文章里写到的优缺点,来自反模式的接口常量
从直观的感受,接口写起来方便多了。
因为类中写的字符比接口多,所以编译之后文件大小也是类文件比接口文件大。
在JVM加载过程中,接口没有类提供的额外特种(如重载、方法的动态绑定等),所以接口加载比类快。
接口是不能阻止被实现或继承的,也就是说子接口或实现中是能够覆盖掉常量的定义,这样通过父、子接口(或实现) 去引用常量是可能不一致的;
同样的,由于被实现或继承,造成在继承树中可以用大量的接口、类或实例去引用同一个常量,从而造成接口中定义的常量污染了命名空间;
接口暗含的意思是:它是需被实现的,代表着一种类型,它的公有成员是要被暴露的API,但是在接口中定义的常量还算不上API。
from p3c.
@Tneciv 之前是顺从Idea的Icons模式来开发的https://www.jetbrains.org/intellij/sdk/docs/reference_guide/work_with_icons_and_images.html,所以在其他地方可能也有这种定义。
@chenxuyuan2016 用接口确实要方便很多,不过既然我们是Java代码规约插件,也应该尽量遵从权威的开发模式,所以在下一个版本会修改为在类中定义或者是kotlin的object定义
感谢大家的意见
from p3c.
Related Issues (20)
- 数组下标越界 HOT 1
- 提几条日常编码时的想法供参考
- 2023.2版本插件报错 HOT 11
- 有没有web的开发手册开发规范
- 规约中有关前后端接口日期时间传递的约定是在挖大坑 HOT 8
- URL Broker 指的是什么
- beta版本试用,增加了对Record类的检测,优化了Switch中default块的判断 HOT 2
- How to add a new rule HOT 69
- stream和enum的格式化能不能优化下
- idea 2023.1.5版本安装规约插件代码规约失效 HOT 1
- How can I use my custom rule which is similar to defined rule? HOT 1
- LockShouldWithTryFinallyRule规则不生效
- 请问下这个插件是没更新了吗? HOT 3
- 类名使用 UpperCamelCase 风格,但以下情形例外:DO / / BO / / DTO / VO / AO / PO / UID 等。这个规则不生效。
- P3C的阿里巴巴网址无法拉取包了
- 这个插件是否已经不维护了
- Gitlab集成P3C检查,如何只对增量代码做检查 HOT 3
- 实时检测功能开启后不生效 HOT 1
- 实时检测功能开启后不生效
- java.lang.ArrayIndexOutOfBoundsException HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from p3c.