java - AutoCloseable metric wrapper -


is semantically correct use autoclosable class wraps block of code , produces time metric? understand there no resource here, concern according http://mail.openjdk.java.net/pipermail/coin-dev/2009-march/000157.html

class metric implements autocloseable {   private final logger logger;   private int starttime;   public metric(logger logger) {     this.logger = logger;   }    static metric createstarted(logger logger) {      metric metric = new metric();      metric.starttimer();      return metric;   }    public starttimer() {      this.starttime = system.milliseconds()   }    @override   public close() {      logger.debug(system.milliseconds() - starttime);   } }  class client { public static void main(string... args) {    try (metric metric = metric.createstarted()) {       // stuff    } } 

there reasons why using lambdas not option here.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -