Hi, This is from K&B mock exam.
Given answer is although String and StringBuffer are both subtypes of CharSequence, they are not necessarily
the same subtype as whatever is passed in (S)..I am not clear. Please let me know
1) S extends CharSequence. It could be any class that extends CharSequence and not necessarily String. What happens if I call fooC(StringBuffer)? Java needs to return a StringBuffer, but the method has a String.
2) What happens if you try to do return (StringBuilder) s.toString(); without generics. Why doesn't it work?
This program compiles with warnings, but runs fine. This is part of the mock questions of the SCJP Java 6 Study Guide for 310-065 (Quiz #56). The given answer to the question is, that both return statements will not compile or they will not run without errors. But the compiler thinks different about that.