Tuesday, April 13, 2010

Compile time error at Runtime

Well what is a Set ? Its simple isn't it ? A collection that doesn't contain any duplicate objects.

But then what ensures that set doesn't end up adding same object in a set twice. What do you think ?

Okay, if you are think it is pretty straight answer to this. What do you do when you end up hearing below as answer.

A: Set implementation ensures no duplicates are added. It throws error, compile time error.

Q: Huh, compile time error ?  What if we have a set which stores employee name and program at run time asks for employee names. User enters and name is then added into the set. How will uniqueness of objects be ensured in set , what will happen if user enters same name twice and program tries to add same name (string) in Set again?

A: As I said an error will be thrown at compile time.

OMG !!! This is new one, compile time error is thrown at runtime. I still am trying to understand, how can this happen. Help me, if possible in understanding this concept. Software industry is indeed moving quickly, I hope I would be able to keep up with the pace its changing :).

1 comment:

  1. You surely have lagged behind. Now a days, whenever a user does something faulty, the JVM on machine where program is running, invokes the compiler on developer's machine & throws error message. It is done in the same way Microsoft tracks all the forwarded chain-emails and pay hefty money in turn.

    ReplyDelete