com.github.phantomthief.util.ToStringHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of more-lambdas Show documentation
Show all versions of more-lambdas Show documentation
Some useful lambda implements for Java 8.
package com.github.phantomthief.util;
import static com.google.common.reflect.Reflection.newProxy;
import java.util.function.Function;
/**
* @author w.vela
*/
public class ToStringHelper {
public static T wrapToString(Class interfaceType, T obj,
Function toStringSupplier) {
return newProxy(interfaceType, (proxy, method, args) -> {
if (method.getName().equals("toString")) {
return toStringSupplier.apply(obj);
} else {
return method.invoke(obj, args);
}
});
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy