import java.util.ArrayList ;
import java.util.List ;
public class Main {
public interface Foo< T> {
T getValue( ) ;
void setValue( T value) ;
}
public static class FooImpl< T> implements Foo< T> {
private T value;
public FooImpl( T value) {
this .value = value;
}
@Override
public T getValue( ) {
return value;
}
@Override
public void setValue( T value) {
this .value = value;
}
}
public static < T> void resetFoos( Iterable< Foo< T>> foos) {
for ( Foo< T> foo : foos) {
foo.setValue ( foo.getValue ( ) ) ;
}
}
public static void main
( String [ ] args
) {
final Foo
< Object
> objFoo
= new FooImpl
<> ( new Object ( ) ) ; final Foo
< Integer
> numFoo
= new FooImpl
<> ( new Integer ( 42 ) ) ; final Foo< String> strFoo = new FooImpl<> ( "asdf" ) ;
List< Foo<?>> foos = new ArrayList<> ( 3 ) ;
foos.add ( objFoo) ;
foos.add ( numFoo) ;
foos.add ( strFoo) ;
resetFoos( foos) ;
}
}
CmltcG9ydCBqYXZhLnV0aWwuQXJyYXlMaXN0OwppbXBvcnQgamF2YS51dGlsLkxpc3Q7CgpwdWJsaWMgY2xhc3MgTWFpbiB7CgogICAgcHVibGljIGludGVyZmFjZSBGb288VD4gewogICAgICAgIFQgZ2V0VmFsdWUoKTsKICAgICAgICB2b2lkIHNldFZhbHVlKFQgdmFsdWUpOwogICAgfQogICAgCiAgICBwdWJsaWMgc3RhdGljIGNsYXNzIEZvb0ltcGw8VD4gaW1wbGVtZW50cyBGb288VD4gewogICAgICAgIAogICAgICAgIHByaXZhdGUgVCB2YWx1ZTsKICAgICAgICAKICAgICAgICBwdWJsaWMgRm9vSW1wbChUIHZhbHVlKSB7CiAgICAgICAgICAgIHRoaXMudmFsdWUgPSB2YWx1ZTsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgQE92ZXJyaWRlCiAgICAgICAgcHVibGljIFQgZ2V0VmFsdWUoKSB7CiAgICAgICAgICAgIHJldHVybiB2YWx1ZTsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgQE92ZXJyaWRlCiAgICAgICAgcHVibGljIHZvaWQgc2V0VmFsdWUoVCB2YWx1ZSkgewogICAgICAgICAgICB0aGlzLnZhbHVlID0gdmFsdWU7CiAgICAgICAgfQogICAgfQoKICAgIHB1YmxpYyBzdGF0aWMgPFQ+IHZvaWQgcmVzZXRGb29zKEl0ZXJhYmxlPEZvbzxUPj4gZm9vcykgewogICAgICAgIGZvciAoRm9vPFQ+IGZvbyA6IGZvb3MpIHsKICAgICAgICAgICAgZm9vLnNldFZhbHVlKGZvby5nZXRWYWx1ZSgpKTsKICAgICAgICB9CiAgICB9CiAgICAKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgICAgICAKICAgICAgICBmaW5hbCBGb288T2JqZWN0PiBvYmpGb28gPSBuZXcgRm9vSW1wbDw+KG5ldyBPYmplY3QoKSk7CiAgICAgICAgZmluYWwgRm9vPEludGVnZXI+IG51bUZvbyA9IG5ldyBGb29JbXBsPD4obmV3IEludGVnZXIoNDIpKTsKICAgICAgICBmaW5hbCBGb288U3RyaW5nPiBzdHJGb28gPSBuZXcgRm9vSW1wbDw+KCJhc2RmIik7CiAgICAgICAgCiAgICAgICAgTGlzdDxGb288Pz4+IGZvb3MgPSBuZXcgQXJyYXlMaXN0PD4oMyk7CiAgICAgICAgZm9vcy5hZGQob2JqRm9vKTsKICAgICAgICBmb29zLmFkZChudW1Gb28pOwogICAgICAgIGZvb3MuYWRkKHN0ckZvbyk7CiAgICAgICAgCiAgICAgICAgcmVzZXRGb29zKGZvb3MpOwogICAgICAgIAogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiZG9uZSIpOwogICAgfQp9