我有以下密码-
Function<String, String> step1 = string -> string + " wakes up";
Function<String, String> step2 = string -> string + "\nbrushes teeth";
Function<String, String> step3 = string -> string + "\ngoes to toilet";
Function<String, String> step4 = string -> string + "\ntakes a shower";
Function<String, String> step5 = string -> string + "\nfeeds the cat";
Function<String, String> step6 = string -> string + "\ncleans litter box";
Function<String, String> step7 = string -> string + "\neats breakfast";
Function<String, String> step8 = string -> string = "\ngoes for work";
String name = "Neha";System.out.println(step1.andThen(step2).andThen(step3).andThen(step4).andThen(step5).andThen(step6).andThen(step7).apply(name));给我输出-
Neha wakes up
brushes teeth
goes to toilet
takes a shower
feeds the cat
cleans litter box
eats breakfast但,
System.out.println(step1.andThen(step2).andThen(step3).andThen(step4).andThen(step5).andThen(step6).andThen(step7).andThen(step8).apply(name));给我输出-
goes for work所以,我想知道这里是否有最多7步的限制。
我正在使用Open 11
发布于 2022-06-04 08:16:23
不是的。看看这个:
Function<String, String> step8 = string -> string = "\ngoes for work";注意赋值操作符=,而不是追加+。
改为:
Function<String, String> step8 = string -> string + "\ngoes for work";而且它应该显示出预期的结果。
为什么Java会随机地将它限制在7个步骤??
https://stackoverflow.com/questions/72498177
复制相似问题