I was trying to run a simple program in scala involving implicit class in scala. The expected output of the program is "CZF" i.e. incrementing each character by 1. But, when i am executing it on Eclipse IDE, its not returning any result nor the error.
object ObjectImplitclass extends App{
implicit class StringIncImplicitClass(s: String){
def increment = s.map(c => (c+1).toChar)
val result = "BYE".increment
print(result)
}
}
When i tried the following chunk of code on terminal:
implicit class StringIncImplicitClass(s: String){
def increment = s.map(c => (c+1).toChar)
val result = "BYE".increment
It returned me "CZF". I am new to the scala syntax, can anyone help me as to why i am not able to see the result on IDE.
In REPL you evaluated
"BYE".incrementright after you defined an implicit class, so result is shown immediately.In IDE you written:
meaning you defined implicit class... but you never used in on anything. If this code is exactly what you have in IDE, it should have been
See the differences in brackets position.