我尝试计算调用静态方法的频率并且不知道该怎么做,因为据我所知,我不能在静态方法中使用实例变量。我有以下课程:
public class Utilities {
// print how often method was called + specific Value of Object o
public static void showObject (Object o) {
System.out.println(counter + ": " + o.toString());
}
}
打印对象值有效,但我怎样才能使计数器计数?因此,以下代码的结果应如下所示:
public static void main (String[] args){
Object objectA = new Object ("Object A", 4);
Object objectB = new Object ("Object B", 4);
Object objectC = new Object ("Object C", 4);
Utilities.showObject(objectB);
Utilities.showObject(objectC);
Utilities.showObject(objectC);
Utilities.showObject(objectA);
1: 3.6
2: 8.0
3: 8.0
4: 9.2
问候和感谢,帕特里克
长风秋雁
繁花不似锦
青春有我
宝慕林4294392
相关分类