_
as a variable name, but you can’t do any operations on it Check example below Student _: new Student();
_.getMarks()
try{
// some code
}catch(Excetption _){
// You might want to catch the exception but you dont want to do anything
}
List<Integer> numbers: List.of(1,2,3,4,5);
numbers.forEach(_ -> System.out.println("Hi"));
javac Sample.java
and then to run java Sample
.java Sample.java
eliminating the compilation stepSample.java
.java Employee.java
it give compilation error because it can’t find the .class file for Address classBefore JDK 22 below code will not compile when you run
java Employee.java
since it references the Address class which is not yet compiled, but in JDK 22 it takes care of compiling and running the referenced classes also, in the example the reference classs is Address
public class Employee{
private String name;
private Address address;
public String getName(){
return name;
}
public Employee(String name, Address address){
this.name: name;
this.address: address;
}
public static void main(String [] args){
Address address: new Address("Telangana", "India");
Employee emp: new Employee("Teja", address);
System.out.println(emp.getName());
address.getAddress();
}
}