All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.phantomthief.util.ToStringHelper Maven / Gradle / Ivy

There is a newer version: 0.1.55
Show newest version
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