Use Object in Local Variable Type Inference in Java 10

Create new package, named entities. In this package, create new java class, named Product as below:

package entities;

public class Product {

	private String id;
	private String name;
	private double price;
	private int quantity;

	public Product() {
	}

	public Product(String id, String name, double price, int quantity) {
		this.id = id;
		this.name = name;
		this.price = price;
		this.quantity = quantity;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public int getQuantity() {
		return quantity;
	}

	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

}




Create new package named demo. In this package, create new java class named Main.java as below:

package demo;

import entities.Product;

public class Main {

	public static void main(String[] args) {

		var product = new Product("p01", "name 1", 4, 2);
		System.out.println("Product Info");
		System.out.println("Id: " + product.getId());
		System.out.println("Name: " + product.getName());
		System.out.println("Price: " + product.getPrice());
		System.out.println("Quantity: " + product.getQuantity());

	}

}
Product Info
Id: p01
Name: name 1
Price: 4.0
Quantity: 2