Home > Mobile >  Long to HexString
Long to HexString

Time:10-12

I have the following Scala snippet:

someLong.formatted("6x")

As a result I receive the hex String.

However, I had to upgrade Scala version and now this line throws the following error:

 method formatted in class StringFormat is deprecated (since 2.12.16): Use formatString.format(value)` instead of `value.formatted(formatString)`, or use the `f""` string interpolator. In Java 15 and later, `formatted` resolves to the new method in String which has reversed parameters.

When I swap formatString with value, as the hint suggest, I got type mismatch.

How can I make it valid, either with the swap or f interpolation?

CodePudding user response:

The f interpolator is a good replacement and allows other text to be added easily:

f"$someLong6x"

f"The result is 0x$someLong6x"
  • Related