日期:2014-05-20 浏览次数:20923 次
import java.util.*; public class test2 { public static void main(String[] args) { Calendar c = Calendar.getInstance(); int index1 = c.get(Calendar.MONTH); System.out.println("现在是今年的第"+index1+1+"个月"); System.out.println("现在是今年的第"+Calendar.MONTH+1+"个月");//上面的是标准,该行是错的, //我的问题是为什么直接用Calendar.MONTH是错的,这个Calendar类的get(~)方法内部是怎么实现 //的呀.实在想不明白.请大神别复制了源代码然后不给解释呐,我看不懂才来问的.大神9我 } }
class A { public static final int MONTH = 0; public static int get(int field) { return 100; } }
------解决方案--------------------
还是先看一下源码
// Field descriptor #98 I public static final int ERA = 0; // Field descriptor #98 I public static final int YEAR = 1; // Field descriptor #98 I public static final int MONTH = 2; // Field descriptor #98 I public static final int WEEK_OF_YEAR = 3; // Field descriptor #98 I public static final int WEEK_OF_MONTH = 4; // Field descriptor #98 I public static final int DATE = 5;