This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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?
Malte Wannerskog wrote:I have a question about this particular question aswell...
the line
compiles and runs just fine without any compiler warnings for me. Am I missing something?
Same goes for
No compiler warnings there aswell. Even though this was not an option in my question.
Thanks for your help
Ah nevermind, I realized that the compiler error didnt occur until you actually try to use the method .
For example with
michael schroeder
Greenhorn
Joined: Feb 23, 2011
Posts: 1
posted
0
Hmm, now I think I am missing something:
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.