We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
To fix the generic val unsupported
final var birds = new Object() { <A> Function<A,A> idiot () { return (Function<A,A>) (a -> a) ;} } ; birds.idiot().apply(7) ; // 7
method is value.
and, iife, also can use this.
The text was updated successfully, but these errors were encountered:
还有这俩也记一下,应该有地方用到
import java.util.HashMap; import java.util.Map; import java.util.function.Function; public class Single { private static Map<Class<?>, Object> instances = new HashMap<>(); public static <T> T instance(Class<T> clazz) throws Exception { if (!instances.containsKey(clazz)) { instances.put(clazz, clazz.getDeclaredConstructor().newInstance()); } return (T) instances.get(clazz); } public static <T, R> Function<T, R> memoize(Function<T, R> function) { Map<T, R> cache = new HashMap<>(); return input -> cache.computeIfAbsent(input, function::apply); } } public class A { public String b = "Hello, world!"; } public class Main { public static void main(String[] args) throws Exception { System.out.println(Single.instance(A.class).b); // 输出:Hello, world! Function<Integer, Integer> square = x -> x * x; Function<Integer, Integer> memoizedSquare = Single.memoize(square); System.out.println(memoizedSquare.apply(5)); // 输出:25 } }
<T, R> Function<Function<T, R>, Function<T, R>> memoize = <T, R> ( f -> { Map<T, R> memoizes = new HashMap<>(); return input -> memoizes.computeIfAbsent(input, f::apply) ; } ) ; // err
Sorry, something went wrong.
No branches or pull requests
To fix the generic val unsupported
method is value.
and, iife, also can use this.
The text was updated successfully, but these errors were encountered: