NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
# 静态方法中的 this --- ## 问题 下面程序片段有没有编译错误?为什么? ``` package com.devin.test; public class Account { public static int level; public static int test() { return this.level; } } ``` ## 结果 第5行有编译错误,因为在静态方法中不能使用this关键字。 ## 结论 #### this 关键字指的是当前的一个引用,而 static 方法与对象无关,是所有对象共享的,所以不能使用 this。