class Test { public static void main(String[] args) { Box stringBox = new Box("123"); stringBox.transform(new Fn >() {}); } static class Box { T value; Box(T value) { this.value = value; } public Box transform(Fn fn) { return new Box(fn.apply(value)); } } interface Fn { B apply(A value); } }