Skip to content

Instantly share code, notes, and snippets.

@bishabosha
Created July 19, 2023 09:48
Show Gist options
  • Save bishabosha/fbab5e8971aa9954b217c1e0dee8b360 to your computer and use it in GitHub Desktop.
Save bishabosha/fbab5e8971aa9954b217c1e0dee8b360 to your computer and use it in GitHub Desktop.
MethodHandles with static fields in scala 3
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