一.导读
在实际开发过程中,我们经常会用到Lombok注解,因为节省了开发效率,本篇文章将介绍Lombok中UtilityClass注解的使用
二.官方提供
1.官方说明
1).It is marked final.
2).If any constructors are declared in it, an error is generated. Otherwise, a private no-args constructor is generated; it throws a UnsupportedOperationException.
3).All methods, inner classes, and fields in the class are marked static.
WARNING: Do not use non-star static imports to import these members; javac won’t be able to figure it out. Use either: import static ThisType.*; or don’t static-import.
2.官方案例
图
三.案例解读
从官方的说明和案例我们可以得知,在使用注释类型UtilityClass声明类后,会得到以下效果
1.类会标记成final最终类
2.属性会标记成静态属性
3.会生成一个私有的无参构造函数,并抛出一个UnsupportedOperationException异常
4.方法会标记成静态方法
四.参考文献
https://projectlombok.org/api/lombok/experimental/UtilityClass.html
https://projectlombok.org/features/experimental/UtilityClass
原文链接:关于Lombok中注解@UtilityClass使用说明,转载请注明来源!