1
 timer.scheduleAtFixedRate(() -> sendTimeToAll(session),0,1,TimeUnit.SECONDS);

This expression is used in java 8, how to write this in java 7 version

1
  • 1
    That depends on the arguments the scheduleAtFixedRate method expects. Commented Jul 26, 2017 at 7:40

2 Answers 2

4

That looks like a Runnable, so you can implement it as a anonymous inner class.

timer.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            sendTimeToAll(session);
        }
    }, 0, 1, TimeUnit.SECONDS);
Sign up to request clarification or add additional context in comments.

Comments

2

The lambda () -> sendTimeToAll(session) is nothing more than a direct implementation of the Runnable-interface.

So () -> sendTimeToAll(session) is equivalent to this

new Runnable() {
    public void run() {
        sendTimeToAll(session);
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.