java8 如何禁用“Use 'var' in declarations”
时间: 2023-11-27 07:50:55 浏览: 39
在Java 8中,没有“var”关键字,因此您不需要禁用它。 “var”是从Java 10开始引入的。
如果您正在使用Java 10或更高版本,并且不想在代码中使用“var”关键字,可以通过在编译时使用“-source”和“-target”选项来禁用它。
例如,如果您使用的是Java 11,并且想要在编译时禁用“var”关键字,可以使用以下命令:
```
javac -source 11 -target 11 -XDallowVarargsForAllMethods -Werror -Xlint:-var-unused -Xlint:-deprecated yourfile.java
```
这将禁用“var”关键字,并显示有关其他潜在问题的警告和错误。
相关问题
modelsim declarations not allowed in unnamed block
This error message typically occurs when you try to declare a variable or signal within an unnamed block in ModelSim. An unnamed block is a region of code enclosed in a pair of curly braces {} that is not associated with a process or function.
To fix this error, you need to move the variable or signal declaration outside of the unnamed block and into the appropriate context. For example, if you are trying to declare a signal within an unnamed block in an architecture, you should move the signal declaration to the architecture declarative region.
Here is an example of how to fix this error:
```
architecture Behavioral of my_entity is
signal my_signal : std_logic;
begin
process
begin
{ -- unnamed block
signal temp_signal : std_logic; -- causes error
}
my_signal <= '1';
end process;
end architecture;
```
Fixed code:
```
architecture Behavioral of my_entity is
signal my_signal : std_logic;
signal temp_signal : std_logic; -- moved signal declaration outside of unnamed block
begin
process
begin
{ -- unnamed block
-- no signal declarations allowed here
}
my_signal <= '1';
end process;
end architecture;
```
可是它说:Static declarations in inner classes are not supported at language level '8'
这个错误是因为在JDK8中,静态声明内部类的语法有所不同。如果您的代码中使用了静态声明内部类的语法,并且出现了上述错误,您可以尝试按照以下步骤解决问题:
1. 打开您的编译器或IDE,并找到项目的设置(一般位于“文件”或“项目”菜单中)。
2. 在设置中找到“编译器”或“编译选项”等相关选项,并打开它。
3. 在编译选项中找到“语言级别”或“Java版本”等相关选项,并将其设置为8。
4. 确认更改并重新编译您的代码。
如果您的编译器或IDE不支持静态声明内部类的语法,您可以尝试使用其他的语法来实现您的需求,例如使用非静态内部类或独立的类来替代静态内部类。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)