<dependency> <groupId>org.babel</groupId> <artifactId>helper-plugin-utilities</artifactId> <version>1.0.0</version> </dependency> import org.babel.plugin.utilities.HelperPluginUtilities; Function<String, String, String> concat = (a, b) -> a + b; Function<String, String> addExclamation = HelperPluginUtilities.createHelperMethod(concat, "!"); System.out.println(addExclamation.apply("Hello")); // Output: Hello! BiFunction<String, Integer, String> repeat = (str, n) -> str.repeat(n); BiFunction<String, Integer, String> addExclamationAndRepeat = HelperPluginUtilities.createChainableMethod(repeat, "!").andThen(repeat); System.out.println(addExclamationAndRepeat.apply("Hello", 3)); // Output: Hello!!!Hello!!!Hello!!! Function<String, Integer> length = String::length; Function<String, String> reverse = str -> new StringBuilder(str).reverse().toString(); Object namespace = HelperPluginUtilities.createNamespace("StringUtils", length, reverse); System.out.println(((Function<String, Integer>) HelperPluginUtilities.getMember(namespace, "length")).apply("Hello")); // Output: 5


上一篇:
下一篇:
切换中文