Not able to call finalize() method on different Object. I am using Eclipse .
I have created object of StringBuilder
StringBuilder sb= new StringBuilder("abc");
sb.finalize(); // compile time error The method finalize() from the type Object is not visible
I have created a 2 classes Test and MyTest with main method in each
public class Test {
public static void main throws Throwable(String [] args ){
Test t= new Test();
t.finalize(); //ok no error
MyTest mt= new MyTest();
mt.finalize() // compile time error The method finalize() from the type Object is not visible
}
}
I have some questions on my mind:
1) As object is super class of all java classes.finalize method must be available because finalize method is protected. Then why eclipse is giving such error ?
2) Is this a bug in eclipse ?
please someone elaborate this concept in details.