What is var in Java 10?

后端 未结 3 804
不思量自难忘°
不思量自难忘° 2021-01-29 08:44

I was reading about the new features released in Java 10 and I found

Java 10 introduced var as a reserve type name to reduce verbosity. It

3条回答
  •  广开言路
    2021-01-29 09:31

    var is something that is already in C#. Basically, instead of declaring a variable type, it assumes its type from what it is being set to. For instance:

    var myString = "Hello world"
    

    Because you are setting it to a value in quotes, it assumes it is a String, rather than having to specify like:

    String myString = "Hello world"
    

提交回复
热议问题