We don\'t have any destructor in Java as we have in C++.
Q1. How should we clean up any Object in java.
Q2. Is there any a
Two syntax sugar options:
1) There is a @Cleanup annotation in Lombok that mostly resembles C++ destructors (more):
@Cleanup
ResourceClass resource = new ResourceClass();
2) There is also try-with-resources statement. For example:
try (BufferedReader br = new BufferedReader(new FileReader(path))) {
System.out.println(br.readLine());
}