不是这个意思。比如: 在一般的类里面如下: public AClass { public Class getThisClass() { return this.getClass(); } }但是如果getThisClass()是个静态方法就不能用this了,怎么办呢?to dlmu6307:right
静态方法是类方法,所以不能在静态方法里调用this 而getClass()方法是针对一个对象返回它的类型 如果你非要在静态方法里使用getclass()的话,可以这样做,不过好像没啥意义 public AClass { public static Class getThisClass() { return AClass.getClass(); } }
写错了 应该是 public AClass { public static Class getThisClass() { return AClass.class; } }
String.classbtw:metarnet?
在一般的类里面如下:
public AClass
{
public Class getThisClass()
{
return this.getClass();
}
}但是如果getThisClass()是个静态方法就不能用this了,怎么办呢?to dlmu6307:right
而getClass()方法是针对一个对象返回它的类型
如果你非要在静态方法里使用getclass()的话,可以这样做,不过好像没啥意义
public AClass
{
public static Class getThisClass()
{
return AClass.getClass();
}
}
public AClass
{
public static Class getThisClass()
{
return AClass.class;
}
}