public class Test { public static void main(String[] args) { Foo foo = new Foo(); foo.setBleh(LOLbject.New("Hello World")); System.out.println(foo.getBleh()); foo.printBlehType(); } } class LOLbject { private T t; private final Class type; public LOLbject(final T t, final Class type) { this.t = t; this.type = type; } public Class getType() { return type; } public T getValue() { return t; } public void setValue(final T value) { this.t = value; } public static LOLbject New(Object o) { return new LOLbject(o,o.getClass()); } } class Foo { private LOLbject bleh; public void setBleh(LOLbject value) { bleh = value; } public T getBleh() { return bleh.getValue(); } public void printBlehType() { System.out.println(bleh.getType()); } }