0

Just starting out with scala and gatling. I am trying to understand code written by another team member. The code is:

UploadFile.uploadFile(vehicle.toString+"firstImage", sessionHeaders, ImagePath,vehicle.toString);

uploadFile is a method in UploadFile.scala and the uploadFile method is defined as:

def uploadFile(name:String, headers:Map[String,String], path:String, param:String)

so vehicle.toString+"firstImage" is the name and is a string. But I dont understand what is vehicle.toString -what is being done here? And then its concatenated to "firstImage". So then why not just write: ` "vehicle" + "firstImage"...?

randbw
  • 490
  • 5
  • 13
RenukaA
  • 25
  • 1
  • 8
  • I'm not a scala expert, but usually toString returns a human-readable representation of an object. – Robert Harvey Mar 11 '20 at 14:27
  • In other words, `vehicle` is probably not a string. If it is, the `toString` call is redundant. – Robert Harvey Mar 11 '20 at 14:27
  • 1
    @RobertHarvey That is not necessarily true, it just returns a **String** representation on an object, if it is human-readable or not is due implementation - RenukaA I suppose vehicle is anything but a string, so in order to concatenate it to another string you first have to turn it into one _(scala has a strong and static type system, not a weak or dynamic one like JS and Python)_ - BTW, usually it would be better to do this using **String interpolation**: `s"${vehicle}firstImage"` – Luis Miguel Mejía Suárez Mar 11 '20 at 14:29
  • Like I said, I'm not a scala expert. If this involves magnetic crystallography or nuclear physics, I'm not personally aware of it. The upshot? if `vehicle` is a object with a type other than string, toString has a purpose; if it's already a string, it probably does not. Run a debugger over it and see what it says. – Robert Harvey Mar 11 '20 at 14:30

1 Answers1

0

vehicle is probably not a String and therefore must be converted to a String before it is concatenated with "firstImage".

If it is already a String, then the .toString is redundant

randbw
  • 490
  • 5
  • 13