是的,可以使用 this
关键字来引用静态成员,因为this
只是引用当前类对象的引用变量。通过对象访问静态变量是不必要的,因此使用 this
来引用静态成员并不是最佳实践。 考虑以下示例。
public class Test
{
static int i = 10;
public Test ()
{
System.out.println(this.i);
}
public static void main (String args[])
{
Test t = new Test();
}
}
运行结果:
10