我试图在本文后面的Java 8中实现Monad接口但是我有以下编译错误
找到2个错误:
File:FunctorsMonads.java [line:36]
错误:FOptional不是抽象的,并且不会覆盖Monad中的抽象方法flatMap(java.util.function.Function>)
File:FunctorsMonads.java [line:50]
错误:名称冲突:FOptional中的flatMap(java.util.function.Function>)和Monad中的flatMap(java.util.function.Function)具有相同的擦除,但都没有覆盖其他
该Functor接口工作得很好.任何帮助深表感谢.
这是代码:
import java.util.function.Function;
public class FunctorsMonads {
public static void main(String[] args) {
System.out.println(tryParse("47"));
System.out.println(tryParse("a"));
FOptional<String> str = FOptional.of("47");
System.out.println(str);
FOptional<FOptional<Integer>> num = str.map(FunctorsMonads::tryParse);
System.out.println(num);
FOptional<Integer> num2 = str.flatMap(FunctorsMonads::tryParse);
System.out.println(num2);
}
static FOptional<Integer> tryParse(String s){
try {
final int i = Integer.parseInt(s);
return FOptional.of(i);
} catch (NumberFormatException e) {
return FOptional.empty();
}
}
}
interface Functor<T, F extends Functor<?, ?>> {
<R> F map(Function<T, R> f); …Run Code Online (Sandbox Code Playgroud) 我正在使用 Spring Boot 3.1.5、 Java21和 maven 3.9.5。我运行时出现以下错误mvn spring-boot:build-image
[INFO] > Pulling builder image 'docker.io/paketobuildpacks/builder:base' 100%
[INFO] > Pulled builder image 'paketobuildpacks/builder@sha256:17ea21162ba8c7717d3ead3ee3836a368aced7f02f2e59658e52029bd6d149e7'
[INFO] > Pulling run image 'docker.io/paketobuildpacks/run:base-cnb' 100%
[INFO] > Pulled run image 'paketobuildpacks/run@sha256:1af9935d8987fd52b2266d288200c9482d1dd5529860bbf5bc2d248de1cb1a38'
[INFO] > Executing lifecycle version v0.16.5
[INFO] > Using build cache volume 'pack-cache-8847f704ad41.build'
[INFO]
[INFO] > Running creator
[INFO] [creator] ===> ANALYZING
[INFO] [creator] Image with name "docker.io/library/elevate-insights:0.0.1-SNAPSHOT" not found
[INFO] [creator] ===> DETECTING
[INFO] [creator] 6 of 26 buildpacks participating …Run Code Online (Sandbox Code Playgroud)