Java错误 - 参数的非法修饰符 - 仅最终允许 [英] Java Error - Illegal Modifier for Parameter - Only final Permitted

查看:558
本文介绍了Java错误 - 参数的非法修饰符 - 仅最终允许的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码有什么问题

public static void main(String[] args){
        public static final String Name = "Robin Wilson";
    }

字符串引用名称显示编译错误 - Java错误 - 非法修改器参数名称 - 只有最终允许

String Reference Name shows Compilation Error - Java Error - Illegal Modifier for Parameter Name - Only final Permitted

可以使用以下给出的建议,但我想了解为什么不允许,尽管两者都是静态的?

Am okay with the below given suggestions, but I want to understand why its not permitted, though both are static?

推荐答案

您已修改过您的问题:


我想理解为什么它不被允许,虽然两者都是静态的?

I want to understand why its not permitted, though both are static?

方法内的变量只存在于堆栈框架上。每次调用方法时,JVM都会创建一个新的堆栈帧,并在方法完成后将其丢弃。

Variables inside a method exist only on the stack frame. The JVM creates a new stack frame every time a method is invoked, and it is discarded once the method completes.

在类,方法和字段上使用 public 关键字来控制访问。没有可以应用于堆栈(本地)变量的访问概念。它只在调用方法时存在于方法内,并且只能在方法中访问。

The public keyword is used on classes, methods, and fields to control access. The is no concept of access that could be applied to a stack (local) variable. It only exists inside the method when it's called, and can only be accessed from within the method.

static 在字段上使用关键字来表示在类的所有实例中只存在一个此类成员,以及将这些成员创建为不需要实例的类成员的方法。堆栈中的任何东西都没有静态的概念;这是暂时的。从方法调用返回后,堆栈框架及其上的所有局部变量将不复存在。

The static keyword is used on fields to denote that only one such member exists across all instances of a class, and on methods to create them as members of the class that do not require an instance. There is no concept of a static state for anything on the stack; it's temporary. The stack frame and all the local variables on it cease to exist once you return from a method call.

基本上,在谈论局部变量时都没有任何意义。

Basically, neither make any sense when talking about a local variable.

这篇关于Java错误 - 参数的非法修饰符 - 仅最终允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆