Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Collections  RSS feed

 
Maxi Malahleha
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Form MasterExam bounus 1.5
Given:
public static void before(){

Set = new TreeSet();

}
public static void after(){
Set<String> set = new TreeSet<String>();

}

My Understanding:
before() and after() will not compile because cant say( Set set = new TreeSet() but you can say ( SortedSet set = new TreeSet())

But
MQC Answer form MasterExam says
Before() will throw an Exception at runtime

Question
Why not say method will not compile.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
before() will not compile because there's no variable name:

Set set = new TreeSet();

With that addition, it would compile fine. SortedSet extends Set, so TreeSet indirectly implements Set, as well.

But it won't throw an exception, either -- if the exam really says that, then my advice would be to make a big fire and throw your book into it; then go get a better book.
[ August 26, 2007: Message edited by: Ernest Friedman-Hill ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!