概要
Javaで「変数宣言で型推論を利用する」の動作を確認してみました。
以下のページを参考にしました。
実装
以下のファイルを作成しました。
JSample9_1.java
class JSample9_1{
public static void main(String[] args){
var old = 24;
var name = "Yamada";
System.out.println("年齢:" + old);
System.out.println("氏名:" + name);
}
}
以下のコマンドを実行しました。
$ javac JSample9_1.java
$ java JSample9_1
年齢:24
氏名:Yamada
まとめ
何かの役に立てばと。