public class Rolex {private final long start;public Rolex() {start = System.currentTimeMillis();}// return time (in seconds) since this object was createdpublic double elapsedTime() {long now = System.currentTimeMillis();return (now - start) / 1000.0;}public static void main(String[] args) {Rolex watchOne = new Rolex();// waste time so it is large enough to be measurabletry {Thread.sleep(500);} catch (InterruptedException e) {}Rolex watchTwo = new Rolex();// waste time so it is large enough to be measurabletry {Thread.sleep(500);} catch (InterruptedException e) {}// right now, watchOne is olderSystem.out.println("watchOne " + watchOne.elapsedTime());System.out.println("watchTwo " + watchTwo.elapsedTime());Rolex watchTmp = watchOne;watchOne = watchTwo;watchTwo = watchTmp;// swapped! now watchTwo is the older one// e.g. watchTwo.elapsedTime() returns a value// (slightly) larger than watchOne.elapsedTime()System.out.println("watchOne " + watchOne.elapsedTime());System.out.println("watchTwo " + watchTwo.elapsedTime());}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。