1

I´m porting a code from Java to Scala and I´m having problems when other Java classes consumes that ported code.

In Java I had

 private void logInfo(Marker marker, Object message, MessageFormatMessage template, Object... objects)

where the method can receive one or many objects Object... objects

In Scala the code it´s ported as

  private def logInfo(marker: Marker, message: Any, template: MessageFormatMessage, objects: Any*): Unit = {

Where I use the one or many objects as Any*

But from Java code it´s cannot be used as it was used before.

Any idea how to do this porting and continue being retro compatible?

Regards.

paul
  • 12,873
  • 23
  • 91
  • 153
  • 5
    You have to tag the method with [`@varargs`](https://www.scala-lang.org/api/current/scala/annotation/varargs.html) to make it compatible with **Java**. - More info can be found [here](https://alvinalexander.com/scala/how-to-annotate-varargs-methods-in-scala-annotation). – Luis Miguel Mejía Suárez Mar 18 '19 at 14:56
  • 1
    wow very nice, I did not know about this tag thanks!!!! – paul Mar 18 '19 at 14:59

0 Answers0