The error message you're seeing indicates that you're trying to instantiate the Stopwatch class from the Google Guava library without providing the required argument. The constructor for Stopwatch is expecting a parameter of type com.google.common.base.Ticker, but you're trying to create a Stopwatch without any arguments.
Here’s a breakdown of what the error message means:
required: com.google.common.base.Ticker - The constructor of Stopwatch you are trying to call requires an argument of type Ticker.
found: no arguments - You are calling the constructor without any arguments.
reason: actual and formal argument lists differ in length - The number of arguments you provided does not match the number required by the constructor.
To resolve this error, you have a couple of options:
Provide a Ticker when constructing the Stopwatch:
You can provide a Ticker, which is an abstraction for reading the current time. You can either use the system ticker or create a custom one. Here's how you can use the system ticker:
Code:
Stopwatch stopwatch = Stopwatch.createStarted(Ticker.systemTicker());
Use the factory method createStarted() or createUnstarted():
Guava provides factory methods that create a Stopwatch using the system ticker by default. If you do not need to provide a custom ticker, you can use these methods:
Code:
Stopwatch stopwatch = Stopwatch.createStarted(); // Automatically starts the stopwatch
Stopwatch unstartedStopwatch = Stopwatch.createUnstarted(); // Creates a stopwatch that is not started
Either of these solutions will help you instantiate Stopwatch correctly, avoiding the constructor issue. Choose the approach that best fits your needs.