龙目岛定制SuperBuilder

2024-01-13

我有两个这样的课程:

@Builder
public class Parent {
    final int a;
    final int b;

    public class static ParentBuilder {
        public ParentBuilder setAllTo(final int value) {
           return a(value).b(value);
        }
    }
}

public class Child extends Parent {
   final in c;

   @Builder(builderMethodName = "childBuilder")
   public Child(final int a, final int b, final int c) {
      super(a, b);
      this.c = c;
   }
}

我的班级正在成长,领域也越来越多。 这是使用的原因@SuperBuilder。但是如何添加自定义的构建器方法呢?

同样的方法也行不通。我尝试了这样的方法:

@SuperBuilder
public abstract class Parent { //yes, I want a abstract parent
    final int a;
    final int b;

    public class static ParentBuilder {
        public ParentBuilder setAllTo(final int value) {
           return a(value).b(value);
        }
    }
}


@SuperBuilder
public class Child extends Parent {
   final in c;

}

Edit

目前还不可能。当我尝试以同样的方式执行此操作时,出现了异常:@SuperBuilder does not support customized builders. Use @Builder instead.
重写是一个像这样的内部类:

public abstract static class ParentBuilder<C extends ParentBuilder, B extends Parent.ParentBuilder<C, B>> {
    // custom imlementations here
}

我最近尝试定制@SuperBuilder使用 Lombok 1.18.8 和 IntelliJ,效果很好。我面临的唯一问题是,我失去了使用的能力toBuilderSuperBuilder 中的标志 -@SuperBuilder(toBuilder=true).

下面是重写 @SuperBuilder 方法的代码。

public static abstract class ChildBuilder<C extends Child, B extends ChildBuilder<C, B>>
        extends ParentBuilder<C, B> {

    private LocalDate date;

    public B date(String dateStr) {
        this.date = LocalDate.parse(dateStr);
        return self();
    }
}

我在这里添加了我的工作代码:在龙目岛自定义 SuperBuilder https://devnip.blogspot.com/2020/09/how-to-override-methods-of-superbuilder.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

龙目岛定制SuperBuilder 的相关文章

随机推荐

  • 直接在视图中绑定模型属性

    我在 Prism 中找到了这段文字文档 http msdn microsoft com en us library gg405484 28v pandp 40 29 aspx 我开始使用 MVVM 但我迷失了方向 我可以 应该 在视图中绑定
  • ggplot2 中的蠕虫图残差图

    I m trying to plot the Worm plot residuals on a model fitted using the gamlss function from the gamlss package The inter
  • 使用 typedcolumn 选择 Spark 数据集

    看着select Spark DataSet 上的函数有各种生成的函数签名 c1 TypedColumn MyClass U1 c2 TypedColumn MyClass U2 这似乎暗示我应该能够直接引用 MyClass 的成员并且类型
  • TypeScript 定义函数的哈希表

    我正在尝试为车把创建一个定义文件 以便与预编译的车把脚本一起使用 Handlebars 会将预编译的脚本放入字符串索引的函数哈希表中 但我无法弄清楚或找到如何定义它 假设的定义是 declare module Handlebars expo
  • 使用连接字段的结果更新文档

    考虑包含以下文档的集合 id aaaaaaaaaaaa title Hello World date Thursday November 12 2015 time 9 30 AM endtime 11 30 AM id bbbbbbbbbb
  • Http-Conduit 频繁连接失败

    我正在编写将通过 HTTP 下载一些文件的应用程序 在某种程度上 我使用以下代码片段来下载页面正文 import network HTTP simpleHTTP getRequest http www haskell org gt gt g
  • 在 VueJS 中使用按钮进行水平滚动

    我希望使用 VueJS 中的按钮实现水平滚动 我有一个容器 其中有几个水平堆叠的 div 我想使用按钮滚动它们 Here https stackoverflow com questions 25028040 jquery horizonta
  • Google reCAPTCHA 的remoteip 参数被忽略

    在 recaptcha 的文档中 https developers google com recaptcha docs verify https developers google com recaptcha docs verify 它说r
  • 在 WPF 窗口中完全删除标题栏的上下文菜单

    I have created a WPF Window and set its Window Style property to None Yet when I press Alt Up Key combination a context
  • nginx 反向代理 - 如何为多个应用程序提供服务

    我正在尝试使用 nginx 构建一个反向代理 以使我的项目中的所有内容都可以从单个地址访问 对于单个服务 以下配置可以正常工作 etc nginx sites enabled reverse proxy conf server listen
  • 将图像存储在 Core Data 中还是作为文件?

    我有一组数据也包含图像 我想缓存这些数据 我应该将它们存储在文件系统还是核心数据上 为什么 有两个主要选项 将文件存储在磁盘上 然后将图像的路径存储在core data中 将图像的二进制数据存储在core data中 我个人更喜欢第一个选项
  • Worklight 6.0.0.1 和 iOS 7 - 屏幕底部出现白条?

    我一直在使用 Worklight 6 0 0 1 我注意到在 iOS 7 上运行的所有 Worklight 应用程序中 屏幕底部有一个白色条的问题 我知道 Worklight 和 iOS 7 的用户之前已经提到过这个问题 IBM Workl
  • Nightwatch 中的 setValue 方法不起作用

    我正在尝试设置一个新的 Nightwatch 项目 以便自动化简单的 Google 搜索页面 我的断言页面上存在的搜索框通过 但我无法对元素执行任何鼠标 键盘操作 Searchbox or SearchButton Note 我正在运行夜巡
  • 将 S3 对象访问限制为来自特定域的请求

    我在 S3 中有视频文件 还有一个通过 src 属性加载文件的简单播放器 我希望只能通过我的网站查看视频 而不是直接通过 S3 URL 这可能在页面的源代码中可见或通过右键单击访问 浏览 AWS 文档 我似乎可以通过 HTTP 执行此操作的
  • Polymer core-ajax跨域问题

    我正在尝试使用 Polymer 进行跨域调用核心ajax http www polymer project org docs elements core elements html core ajax成分 我不断收到请求的资源上没有 Acc
  • 防止 ModalPopupExtender 在回发期间/之后关闭

    如何防止我的 asp ModalPopupExtender 在回发到服务器之后或期间关闭 这是我的代码 脚本语言 Confirm popup Ok button function OnOk confirmPopup hide ClickSa
  • 如何禁用网络音频分析仪过滤高频

    I am studying the html5 audio API I have noticed the analysis module has problems processing high frequencies It is as i
  • 单个 UILabel 中的粗体和非粗体文本?

    如何在 uiLabel 中同时包含粗体和非粗体文本 我不想使用 UIWebView 我也读过使用 NSAttributedString 可能可以实现这一点 但我不知道如何使用它 有任何想法吗 Apple achieves this in s
  • Mongo查询在mongo shell中有效,但在bash mongo --eval中无效?

    这是一个示例查询 db readings find id s ISODate 2012 11 01T00 05 00Z count 查询在 mongo shell 中工作 但是 在 bash 脚本中或直接在 Ubuntu shell 中 m
  • 龙目岛定制SuperBuilder

    我有两个这样的课程 Builder public class Parent final int a final int b public class static ParentBuilder public ParentBuilder set