Timer java code does not work
public interface IncDec
{
void increment();
void decrement();
}
public class MyIncDec implements IncDec
{
private int x;
public MyIncDec(int x) {
this.x = x;
}
public void increment() {
this.x++;
}
public void decrement() {
this.x--;
}
}
Part 1: Implement a class which can be used to measure how long each invocation of the increment and decrement method takes (in
milliseconds) and prints out this information. The class should fit in more or less transparently with existing clients of the IncDec interface.
My Solution:
public class Test{
public static void main(String[] args){
MyIncDec mid = new MyIncDec(4);
long l1;
long l2;
l1 = Calendar.getInstance().getTimeInMillis();
mid.increment();
l2 = Calendar.getInstance().getTimeInMillis();
System.out.println(l2-l1);
}
}
My Solution gives me the time diff as 0. When I display the long values before n after calling 'increment', They are the same. Why so?
Thanks,