• java开发神器Lombok初识


    一、前言

      在我们使用java语言定义实体对象的时候,以前经常需要写set和get方法,会觉得很繁琐。偶然接触到一款神器叫Lombok的,可以帮我们很好的解决这种琐事。

    二、步骤

      1、在idea上安装Lombok插件

      File-Settings-Plugins,搜索Lombok

      

       下载后,需要重启idea生效

      2、在pom文件添加相关依赖

            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.20</version>
                <scope>provided</scope>
            </dependency>

    三、测试类

    import lombok.Data;
    
    @Data
    public class Text {
    
        private String content;
    }

    idea编译之后的:

    //
    // Source code recreated from a .class file by IntelliJ IDEA
    // (powered by Fernflower decompiler)
    //
    
    package restassureddemo.weixin;
    
    public class Text {
        private String content;
    
        public Text() {
        }
    
        public String getContent() {
            return this.content;
        }
    
        public void setContent(String content) {
            this.content = content;
        }
    
        public boolean equals(Object o) {
            if (o == this) {
                return true;
            } else if (!(o instanceof Text)) {
                return false;
            } else {
                Text other = (Text)o;
                if (!other.canEqual(this)) {
                    return false;
                } else {
                    Object this$content = this.getContent();
                    Object other$content = other.getContent();
                    if (this$content == null) {
                        if (other$content != null) {
                            return false;
                        }
                    } else if (!this$content.equals(other$content)) {
                        return false;
                    }
    
                    return true;
                }
            }
        }
    
        protected boolean canEqual(Object other) {
            return other instanceof Text;
        }
    
        public int hashCode() {
            int PRIME = true;
            int result = 1;
            Object $content = this.getContent();
            int result = result * 59 + ($content == null ? 43 : $content.hashCode());
            return result;
        }
    
        public String toString() {
            return "Text(content=" + this.getContent() + ")";
        }
    }

      说明生效

    知道、想到、做到、得到
  • 相关阅读:
    安卓系统的文件管理神器Solid Explorer(v2.2)
    地月距离竟然如此遥远
    Android在争议中逃离Linux内核的GPL约束【转】
    gearman
    PHP基础学习
    函数式编程
    有向图的实现
    无向图的实现
    百度地图API获取数据
    python队列的实现
  • 原文地址:https://www.cnblogs.com/Durant0420/p/14954565.html
Copyright © 2020-2023  润新知