/* package whatever; // don't place package name! */
import java.util.* ;
import java.lang.* ;
import java.io.* ;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
List< Integer> doesNotWork = new ArrayList< Integer> ( ) ;
doesNotWork.add ( 1 ) ;
doesNotWork.add ( 2 ) ;
doesNotWork.add ( 3 ) ;
Test tst = new Test( ) ;
//tst.setList(doesNotWork);
Test.
class .
getMethod ( "setList" ,
List .
class ) .
invoke ( tst, doesNotWork
) ; tst.showLengths ( ) ; // <<== However, this will now break.
}
}
class Test {
private List< String> myList;
public void setList( List< String> list) {
myList = list;
}
public void showLengths( ) {
System .
out .
println ( "Inside showLengths..." ) ; System .
out .
println ( s.
length ( ) ) ; }
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgoJewogICAgICAgIExpc3Q8SW50ZWdlcj4gZG9lc05vdFdvcmsgPSBuZXcgQXJyYXlMaXN0PEludGVnZXI+KCk7CiAgICAgICAgZG9lc05vdFdvcmsuYWRkKDEpOwogICAgICAgIGRvZXNOb3RXb3JrLmFkZCgyKTsKICAgICAgICBkb2VzTm90V29yay5hZGQoMyk7CiAgICAgICAgVGVzdCB0c3QgPSBuZXcgVGVzdCgpOwogICAgICAgIC8vdHN0LnNldExpc3QoZG9lc05vdFdvcmspOwogICAgICAgIFRlc3QuY2xhc3MuZ2V0TWV0aG9kKCJzZXRMaXN0IiwgTGlzdC5jbG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