Out of curiosity I came to write the following method:
public Object getObject() {
return this.getObject();
}
Why would Java allow me to write this? This method would never return any Object and would result in a StackOverflow Error.
1. I don't think compiler will have any objection in giving a clearance on your above code..i think its just how
recursionis written and used.2. Here this code will cause a problem during
runtime, and so its entirely a problem with logic that the programmer has written, so it won't bother the compiler, but during runtime the Error will be thrown......If compilers would have been this smart..... then Terminator movie would have been a near reality.....