本文介绍了在字段声明中使用var的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,从Java 9开始,我们可以使用var声明局部变量:

So starting in Java 9, we can use var to declare local variables:

var s = "cool";

有什么方法可以在声明字段时使用类似的构造?

is there a way to use a similar construct when declaring fields?

class Container {
  final var s = "cool"; // does not compile tmk
}

从我的判断来看,

看起来并不像.

doesn't seem like it from what I can tell.

推荐答案

不.

根据 JEP 286:局部变量类型推断:

这篇关于在字段声明中使用var的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 17:58
查看更多