class BooleanWrap{
boolean b = new Boolean("true").booleanValue();
}
When I try to do the same with the code below, it doesn't work:
class TestCode {
public static void main(String[] ar) {
TestCode tc = new TestCode().go();
}
void go() {
//some code
}
}
Compile error:
TestBox.java:6: error: incompatible types TestBox t = new TestBox().go();
When I change the return type of method go()
from void
to class type, then I do not get the error anymore.
class TestCode2 {
public static void main(String[] ar) {
TestCode2 tc2 = new TestCode2().go();
}
TestCode2 go() {
//some code
}
}
What happens to the object I just created in above code (referenced by tc2
)? Will it get abandoned?