سؤال

How does Scala get type safety on the f method String interpolation. The StringContext.f method takes args of Any. So how is it able to tell whether an Int, Double etc are required:

def f(args: Any*): String

هل كانت مفيدة؟

المحلول

Method f is implemented as macro.

In compile time macro implementation is called. Here is the source or implementation.

Method f is defined as def f(args: Any*): String, but macro implementation can get actual parameters types (as args: List[Tree]) and actual string content.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top