[英]Lombok And Java Static Constructor Object Creation
Official document says that I can create object by using following approach:官方文档说我可以使用以下方法创建对象:
@Data(staticConstructor = "of")
class Foo<T> {
private T x;
}
you can create new instances of Foo by writing: Foo.of(5);您可以通过编写以下内容来创建 Foo 的新实例: Foo.of(5); instead of having to write: new Foo(5);而不必写: new Foo(5);
This is a sample method to learn lombok.这是学习 lombok 的示例方法。
package com.lombok.first;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.val;
@Data public class DataAnnot {
@Getter @Setter private String name;
private final int salary;
@ToString(includeFieldNames=true)
@Data(staticConstructor="of")
public static class inner<T>{
private T tally;
}
public static void main(String agrs[]){
DataAnnot d= new DataAnnot(8);
System.out.println(d);
}
}
but when I add the line但是当我添加这一行时
val obj= inner.of("object");
System.out.println(d);
Eclipse flags error. Eclipse 标记错误。 What am I missing here?我在这里缺少什么? Perhaps I need to refresh my generics concepts, but how can I create an object of "inner" class?也许我需要刷新我的泛型概念,但是如何创建“内部”类的对象?
Maybe you should use val obj = DataAnnot.inner.of("object");
也许你应该使用val obj = DataAnnot.inner.of("object");
? ?
I cannot tell for sure since you didn't specify where you added the code snippet.我不能确定,因为您没有指定添加代码片段的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.