我试图从这里复制一个简单的对象分解示例。我已将以下依赖项添加到我的项目中:
<dependency>
<groupId>io.vavr</groupId>
<artifactId>vavr</artifactId>
<version>${vavr.version}</version>
</dependency>
<dependency>
<groupId>io.vavr</groupId>
<artifactId>vavr-match</artifactId>
<version>${vavr.version}</version>
</dependency>
<dependency>
<groupId>io.vavr</groupId>
<artifactId>vavr-match-processor</artifactId>
<version>${vavr.version}</version>
</dependency>
…在哪里 vavr.version
是 0.10.3
并复制粘贴了上述来源的示例:
import io.vavr.Tuple;
import io.vavr.Tuple2;
import io.vavr.match.annotation.Patterns;
import io.vavr.match.annotation.Unapply;
import lombok.AllArgsConstructor;
import lombok.Getter;
import static io.vavr.API.$;
import static io.vavr.API.Match;
import static io.vavr.API.Match.*;
public class Example {
@Getter
@AllArgsConstructor
public static class Employee {
private String name;
private String id;
}
@Patterns
public static class Demo {
@Unapply
static Tuple2<String, String> Employee(Employee Employee) {
return Tuple.of(Employee.getName(), Employee.getId());
}
}
public static void main(String[] args) {
Employee person = new Employee("Carl", "89696D8");
String result = Match(person).of(
Case(Demo.Employee($("Carl"), $()), (name, id) -> ""),
Case($(), () -> "notfound")
);
}
}
但是第一个 Case
产生编译错误 Expected 1 argument but found 2
这就意味着注解处理没有起作用,相应的模式也没有生成。如果我错了,请纠正我。
我正在使用intellij 2020.1并在其中启用了注解处理
暂无答案!
目前还没有任何答案,快来回答吧!