Created
July 19, 2023 09:48
-
-
Save bishabosha/fbab5e8971aa9954b217c1e0dee8b360 to your computer and use it in GitHub Desktop.
MethodHandles with static fields in scala 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package foo | |
import scala.annotation.static | |
import java.lang.invoke.{MethodHandle, MethodHandles, MethodType} | |
class MH | |
object MH: | |
@static private val lookup = MethodHandles.lookup() | |
@static private val String_charAt: MethodHandle = | |
lookup.findVirtual(classOf[String], "charAt", MethodType.methodType(classOf[Char], classOf[Int])) | |
@main def test: Unit = | |
println(String_charAt.invokeExact("abc", 1): Char) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment