timer - Lambda Schedule to println from a ArrayList -


i trying create timer print out arraylist @ schedule. receiving error:

cannot resolve method 'schedule(<lambda expression>,int,java.util.concurret.timeunit)' 

why receiving error , can it?

list<string> finalquestionslist = questionslist; timer.schedule(()-> finalquestionslist.foreach(write::println),120, timeunit.seconds);  

jls asserts type of lambda expression:

a lambda expression compatible in assignment context, invocation context, or casting context target type t if t functional interface type (§9.8) , expression congruent function type of ground target type derived t.

  1. timertask not function interface, can't assign lambda expression timertask. can adaptee runnable timertask adapter method task.

  2. timer.schedule methods can't take timeunit, can using timeunit.tomills() convert duration milliseconds.

  3. i can't see write variable in code snippet, use system.out instead.

    list<string> finalquestionslist = questionslist; timer.schedule(task(() -> finalquestionslist.foreach(system.out::println))          , 120, timeunit.seconds.tomillis(1));  private timertask task(runnable task) {     return new timertask() {       @override       public void run() {         task.run();       }     }; } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -