-4

In the WWW I find interview question and one of them is:

What will be the output of the code snippet below:

class Kondana<T:Equatable> {
    var dictDataHolder = [String:T]()
    func add(value:T?,using key:String) -> T? {
         self.dictDataHolder[key] = value
         return value
    }
}
var fortOne = Kondana<String>()
let value = fortOne.
print(value)

Answers are:

a) British
b) nil
c) compile-time error
d) segmentation fault

I am run this code in Xcode and my output is:

__lldb_expr_21.Kondana<Swift.String>

Help me please understand what is going on step by step. I have thoughts about what is going on but not sure about them. What is Kondana class and why use the syntax like above, I know that is generic but not understand the output?

Ice
  • 680
  • 1
  • 10
  • 23
  • 3
    the code you posted isn't complete - this line is cut short `let value = fortOne.` – New Dev Apr 08 '21 at 13:29
  • Can you more information about the interview which may clarify the answer people here could do ? – Ptit Xav Apr 08 '21 at 13:33
  • 2
    When you ran it, you put "let value = fortOne" instead of "let value = fortOne." and that printed a representation of what fortOne is - actually it should have given a syntax error at the . character – Shadowrun Apr 08 '21 at 14:04

1 Answers1

0

With the code posted, the correct answer is "compile-time error". As others have said, the line

let value = fortOne. 

is truncated, and is therefore not legal.

Duncan C
  • 128,072
  • 22
  • 173
  • 272